How to determine if the user has administrator privileges ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to determine if the user has administrator privileges ?

Mark Pirogovsky-3
Hello Everybody,

There are ways to find out if the current user has administrator
privileges on the Win32 box.  Many windows programs do that.  I wonder
if there is an easy way to do this from inside the VW, before I start
compiling C code into  win32 EXE or DLL?

TIA,

--Mark Pirogovsky

some refs:

http://vcfaq.mvps.org/sdk/21.htm
http://support.microsoft.com/kb/q118626/

Reply | Threaded
Open this post in threaded view
|

RE: How to determine if the user has administrator privileges ?

Boris Popov, DeepCove Labs (SNN)
NSIS has a function that does just that,

http://nsis.sourceforge.net/IsUserAdmin

See source code at,

http://tinyurl.com/jqopc

Hope this helps,

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Mark Pirogovsky [mailto:[hidden email]]
Sent: Wednesday, May 03, 2006 8:11 AM
To: [hidden email]
Subject: How to determine if the user has administrator privileges ?

Hello Everybody,

There are ways to find out if the current user has administrator
privileges on the Win32 box.  Many windows programs do that.  I wonder
if there is an easy way to do this from inside the VW, before I start
compiling C code into  win32 EXE or DLL?

TIA,

--Mark Pirogovsky

some refs:

http://vcfaq.mvps.org/sdk/21.htm
http://support.microsoft.com/kb/q118626/


smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if the user has administrator privileges ?

Andre Schnoor
In reply to this post by Mark Pirogovsky-3

> There are ways to find out if the current user has administrator
> privileges on the Win32 box.  Many windows programs do that.  I wonder
> if there is an easy way to do this from inside the VW, before I start
> compiling C code into  win32 EXE or DLL?
>

Hi Mark,

while there is an API for that in Win2k and XP (at least there should be
a 'IsUserAnAdmin' function), however it is missing(!) in my own Win2k
installation. Whatever the reason is, determining if an user is admin
can be *hell*, especially if you want to do it right and fight with the
weird MS philosophy of ad-hoc API design ....

I chose to do it brute force and simple: If setting a registry entry in
a locked area of the registry fails, the user is NOT an admin:

WinNTSystemSupport>>userIsAdmin
    "Answer true, if the user has Administrator rights. This is not
supported
     by all versions of Win2K or XP, so we need a hack here."
    | path key value admin |
    path := #( 'Hardware' 'Description' ).
    key := 'TestAdmin'.
    value := 'TestValue'.
    "Only an admin can write to this path:"
    self setRegistry: #HKEY_LOCAL_MACHINE path: path key: key value:
value type: #REG_SZ.
    admin := self getRegistry: #HKEY_LOCAL_MACHINE path: path name: key
ifAbsent: nil.
    self removeRegistry: #HKEY_LOCAL_MACHINE path: path name: key
ifAbsent: nil.
    ^admin notNil and:[ admin = value ]


I'm not sure if the registry setting methods are custom, but it should
be no problem to use the built-in methods.

HTH
Andre