Page 1 of 1

User mode installing??

Posted: Sun Mar 19, 2006 1:26 am
by DoubleDutch
When in user mode, where can you install programs to? Whats the official API call to find this location (if it exists!)...

Posted: Sun Mar 19, 2006 1:49 am
by DoubleDutch
I also need to know how to detect if the user has administrative rights or none at all.

Posted: Sun Mar 19, 2006 7:35 am
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

Posted: Sun Mar 19, 2006 7:38 am
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 

Posted: Sun Mar 19, 2006 10:35 am
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

Posted: Sun Mar 19, 2006 11:15 am
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

Posted: Fri Jan 18, 2008 6:18 am
by PB
For Windows 2000 and higher:

Code: Select all

Debug IsUserAnAdmin_() ; 1=Yes, 0=No

Posted: Fri Jan 18, 2008 11:51 am
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.