
IsAdministrator()
Well PB's IsUserAdmin_() seems to work as well on 2000/XP/Vista, but I can't find it documented anywhere except for WINE.
I'll stay with my my code for now, but it is really amazing that a simply question "do I have admin privs" could lead to so many answers.
Thanks everybody.
I'll stay with my my code for now, but it is really amazing that a simply question "do I have admin privs" could lead to so many answers.
Thanks everybody.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
You can also use this:
Code: Select all
Procedure IsAdmin()
a=OpenSCManager_(0,0,#SC_MANAGER_ALL_ACCESS)
If a : CloseServiceHandle_(a) : EndIf
ProcedureReturn a
EndProcedure
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
what exactly is this supposed to return if the user is admin? It returns a random 7 digit numer for me if the user is admin...so if it returns anything except 0 its working?PB wrote:You can also use this:
Code: Select all
Procedure IsAdmin() a=OpenSCManager_(0,0,#SC_MANAGER_ALL_ACCESS) If a : CloseServiceHandle_(a) : EndIf ProcedureReturn a EndProcedure
The others return either 1 or 0.
@SFSxOI: Sorry, it's 0 if not admin, or non-0 if it is. Or it can use 1/0 like this:
It was originally coded like opening a window: 0 if failed, or non-0 for success.
Most PureBasic and API commands work that way, so I just did the same.
Code: Select all
Procedure IsAdmin()
a=OpenSCManager_(0,0,#SC_MANAGER_ALL_ACCESS)
If a : CloseServiceHandle_(a) : a=1 : EndIf
ProcedureReturn a
EndProcedure
Most PureBasic and API commands work that way, so I just did the same.

I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
OpenSCManager_ returns a 0 if access fails.
If access is granted, it returns the handle to the SCManager.
You could then use functions like openService_ or controlService_ or startService_ to work with services.
If the first paremeter of SCManager is a pointer to a string, you can connect to SCManagers of a remote PC.
All explained in the good old win32.hlp file.
If access is granted, it returns the handle to the SCManager.
You could then use functions like openService_ or controlService_ or startService_ to work with services.
If the first paremeter of SCManager is a pointer to a string, you can connect to SCManagers of a remote PC.
All explained in the good old win32.hlp file.
PB 5.40 LTS, W7,8,10 64bit and Mint x64