Page 2 of 2
Posted: Wed Feb 27, 2008 12:49 am
by SFSxOI
I saw this previously and thought this was for win2K and XP only so i ignored it. Seems to work here OK on Vista Ultimate. But....wichtel's latest code is smaller and works also, so i'm going to use that one. Thank you

Posted: Wed Feb 27, 2008 9:35 am
by wichtel
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.
Posted: Wed Feb 27, 2008 10:17 am
by PB
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
Posted: Wed Feb 27, 2008 10:48 am
by wichtel
@PB:
Hey, hey, that is what I posted first in that thread. It worked but I always thought doing that way is "not professional"
But you are right that works for NT/2000/XP/VISTA.
And it has the advantage that you could poll remote machines.
Posted: Wed Feb 27, 2008 11:57 am
by PB
> that is what I posted first in that thread

I need to open my eyes more.

Posted: Wed Feb 27, 2008 12:04 pm
by SFSxOI
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
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?
The others return either 1 or 0.
Posted: Wed Feb 27, 2008 12:08 pm
by PB
@SFSxOI: Sorry, it's 0 if not admin, or non-0 if it is. Or it can use 1/0 like this:
Code: Select all
Procedure IsAdmin()
a=OpenSCManager_(0,0,#SC_MANAGER_ALL_ACCESS)
If a : CloseServiceHandle_(a) : a=1 : EndIf
ProcedureReturn a
EndProcedure
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.

Posted: Wed Feb 27, 2008 12:15 pm
by SFSxOI
@PB; thats what I thought but wanted to make sure. Thanks

Posted: Wed Feb 27, 2008 12:32 pm
by wichtel
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.