Archive: administrator check


administrator check
  Has anyone the isadmin.dll?
I searched everywhere and can't find it..
I really need it.

also
Is there a registry key that determines that if the current user logged on is an Administrator or not?

Something like e.x.
if the current user is an admin then the key will be 1
if the current user is not an admin the key will be 0

or an environmental variable?


Try the UserInfo plugin which comes with NSIS. There is an example script in the Contrib\UserInfo folder.


There is an undocumented Windows API call for this in the shell32.dll. As part of the Microsoft settlement Microsoft was force to expose a portion of them. One I'm referring to is: ordinal# 680 a.k.a. IsUserAnAdmin.

It exist, I believe, in all NT based platforms. I remember only verifying its existence and it working on NT4 and up.

The bad news is:
It does not contain a function name - only an ordinal#. I believe Microsoft began including the function name in XP, but I don't know if it was always there or introduced in a later service pack.

This is how you would call it in XP using its function name:
System::Call 'shell32::IsUserAnAdmin(v)i .r1'

Unfortunately, I don't believe you can call functions by ordinals using the System.dll plugin - though - I think it would be a nice feature to have included in a future revision to the plugin.

The good news is: You could create your own plugin to call the function via its ordinal yourself.

I hope this was informative if nothing else... ;)

jc3


System::Call "kernel32::GetModuleHandle(t 'shell32.dll') i .s"
System::Call "kernel32::GetProcAddress(i s, i 680) i .r0"
System::Call "::$0() i .r0"
DetailPrint "is admin? $0"

kichik,

You never seize to amaze...

:up:

jc3


just packed above into a function for less advanced users
  code:


Function CheckAdminRights
System::Call "kernel32::GetModuleHandle(t 'shell32.dll') i .s"
System::Call "kernel32::GetProcAddress(i s, i 680) i .r0"
System::Call "::$0() i .r0"

IntCmp $0 0 isNotAdmin isNotAdmin isAdmin
isNotAdmin:
DetailPrint "Missing Administrator Rights !!!"
messageBox MB_YESNO|MB_DEFBUTTON2 "Die aktuellen Benutzer-Rechte sind zu gering!$\r\
Für die Installation werden Administrator-Rechte benötigt!$\r\
um Bibliotheken (.dll-files) zu registrieren.$\r\
$\r\
Im Fall eines Updates können die aktuellen Rechte dennoch ausreichen.$\r\
$\r\
Soll die Installation ohne Administrator-Rechte fortgesetzt werden ?" IDYES isAdmin
quit

isAdmin:
DetailPrint "Administrator Rights granted"

FunctionEnd


I use the following for validation of Administrator user
(not sure where i got it from)

ClearErrors
UserInfo::GetName
IfErrors Win9x
Pop $0
UserInfo::GetAccountType
Pop $1
StrCmp $0 "Administrator" 0 +3 ;
Goto done
StrCmp $1 "Power" 0 +3
MessageBox MB_OK 'You Must be logged in as Administrator!'
Quit ;
StrCmp $1 "User" 0 +3
MessageBox MB_OK 'You Must be logged in as Administrator!'
Quit ;
StrCmp $1 "Guest" 0 +3
MessageBox MB_OK 'You Must be logged in as Administrator!'
Quit ;
MessageBox MB_OK "Unknown error"
Quit ;

Win9x:
# This one means you don't need to care about admin or
# not admin because Windows 9x doesn't either
MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"

done:


Fish

fishweasel, you got this from Examples\UserInfo which is the examples folder for the plug-in written exactly for this purpose.


Hi
It does not work in Windows Seven

Function .onInit


>##############################
# GetAccountType #
##############################
>ClearErrors
UserInfo::GetAccountType
IfErrors+3
Pop$0
StrCmp$0 "Admin" begin
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "This user is not an administrator!!"
>Quit
begin:
Why؟

Where is the problem؟
StrCmp$0 "Admin" begin
MessageBox MB_OK
|MB_ICONSTOP|MB_TOPMOST "$0"

>A message window MessageBox is the Just type A

Can you please write me a code sample
>!!
Thanks For Hellp- if

I compiled the example program that comes with NSIS and it ran fine on my Windows 7 system. (I added "RequestExecutionLevel user" to stop UAC from asking me to elevate before it executed the test program.) With elevation, it shows that I am Admin. Without elevation it shows that I am User.

Take another look at the example program.