User mode installing??

Windows specific forum
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

User mode installing??

Post by DoubleDutch »

When in user mode, where can you install programs to? Whats the official API call to find this location (if it exists!)...
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I also need to know how to detect if the user has administrative rights or none at all.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

For admin right :

Code: Select all

ProcedureDLL IsUserAnAdmin()
  ; Changed in 1.2 because don't work with Impersonate : This version Works great
  ret = openSCmanager_(#Null,#Null,#SC_MANAGER_ALL_ACCESS) 
  If ret 
    closeServiceHandle_(ret) 
  EndIf 
  If ret>0 : ret =1 : EndIf
  ProcedureReturn ret 
EndProcedure
User avatar
Droopy
Enthusiast
Enthusiast
Posts: 658
Joined: Thu Sep 16, 2004 9:50 pm
Location: France
Contact:

Post by Droopy »

For install directory use 38 as value :

Code: Select all

ProcedureDLL.s GetSpecialFolderLocation(Valeur.l) 
  If SHGetSpecialFolderLocation_(0, Valeur, @Dossier_ID) = 0 
    SpecialFolderLocation.s = Space(#MAX_PATH) 
    SHGetPathFromIDList_(Dossier_ID, @SpecialFolderLocation) 
    If SpecialFolderLocation 
      If Right(SpecialFolderLocation, 1) <> "\" 
        SpecialFolderLocation + "\" 
      EndIf 
    EndIf 
  EndIf 
  ProcedureReturn SpecialFolderLocation.s 
EndProcedure 
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

For admin right :
etc...
Thanks, I will use this. :) At present I'm just using a hack that tries to create a file where it shouldn't. An error means its user mode. ;)
For install directory use 38 as value :
etc...
I figured this one out by looking at what happens to 'google earth'. But thanks all the same. :)

For those others reading this who also have a similar problem, don't forget to move over to CURRENT_USER in registry settings rather than CURRENT_MACHINE (if user mode detected).

Lots of programs have the the problem where thay will say "no access rights" when trying to install (including PureBasic!). The above info provided by Droopy will help you bypass these errors completely.

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Droopy, #38 ALWAYS returns Program Files - if in user or admin mode...

If in user mode you should use the program data path or similar as that is useable, it doesn't look right however - i'd rather use the dir above the program data path - google earth uses this.

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

For Windows 2000 and higher:

Code: Select all

Debug IsUserAnAdmin_() ; 1=Yes, 0=No
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

DoubleDutch wrote:
For admin right :
etc...
Thanks, I will use this. :) At present I'm just using a hack that tries to create a file where it shouldn't. An error means its user mode. ;)
Wouldn't it be better to get the program files directory, then use some windows API function to see whether you can write there rather than checking whether a user is an admin or not?

This page seems to explain how to do it (in C) but I've not tried it: http://www.devx.com/cplus/Article/16711/1954?pf=true

By default XP comes configured with 3 user groups - administrators, power users and users. Administrators and power user can both install software on a per machine basis, but a power user would not show up as an administrator and probably wouldn't have full control over the service manager.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Post Reply