Archive: Userinfo working once


Userinfo working once
  I use UserInfo to check for admin rights. This works allrightthe first time, but when my application is uninstalled and after that again installed the userinfo returns an empty string instead of the admin string I would expect. My install ends, but when I restart it the admin rights are detected okay and everything works like a charm. Anyone else have this problem? Is there a solution to this problem?

Jorrit


Can you attach the script?


These should be the relevant parts of the script:

<knip>
!macro ADMIN_CHECK

; Bij windows 9x werkt deze routine niet, dus checken
!insertmacro WINVERSION
StrCpy $6 $R0
StrCmp $6 "Windows 98" Win9x 0
StrCmp $6 "Windows ME" Win9x +3
Win9x:
StrCpy $6 "Win9x"
Goto NoCheck

UserInfo::GetAccountType
Pop $R0
StrCmp $R0 "Admin" +3 0
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "U moet beheerder zijn van het systeem om deze installatie uit te kunnen voeren. U bent: $R0"
Abort
NoCheck:
!macroend

!macro WINVERSION
WinVer::GetWindowsVersion
Pop $R0 ; De Windows versie
Pop $R1 ; Eventueel het service pack
!macroend

Function .onInit
!insertmacro ADMIN_CHECK
!insertmacro CHECK_MSDE
!insertmacro AFTERREBOOT
FunctionEnd
<knip>

Jorrit


So you start the installer in a normal way (using explorer or something else) and you get a message that says "U bent: " (empty)?


Yes, exactly.
And if I try again it sometimes works or I have to try again. It would take a few tries and then there is no problem.
But... it never happens on the initial install, or has never happened so far....
Jorrit


What is your OS? Can you try to reproduce it with another installer? Are you sure it always works on the initial install, or is it just random?


Hmm,
this happened on a NT4 and a win2k machine, but I can't reproduce anymore. It's gone. I've had this happen at least ten times this morning, but it doesn't happen anymore. I've changed some things, but nothing that should influence any of this... So I hope it's gone


Too soon.... it's not back, it just happens less....
NT4 machine. What I see is that the DLL Winver has been put in my install dir.... Is this the default behaviour?


1)

StrCmp $6 "Windows 98" Win9x 0
StrCmp $6 "Windows ME" Win9x +3
Win9x:
StrCpy $6 "Win9x"
Goto NoCheck

UserInfo::GetAccountType
Pop $R0
StrCmp $R0 "Admin" +3 0
MessageBox MB_OK|MB_ICONSTOP|MB_TOPMOST "U moet beheerder zijn van het systeem om deze installatie uit te kunnen voeren. U bent: $R0"
Abort
NoCheck:
Replace the code above by this:

StrCmp$6 "Windows 98" +2 0 

StrCmp$6 "Windows ME" 0 DetectAdmin
StrCpy$6 "Win9x"
>Goto AdminCheckEnd

DetectAdmin:
>UserInfo::GetAccountType
Pop $R0

StrCmp $R0"Admin" AdminCheckEnd
MessageBox MB_OK
|MB_ICONSTOP|MB_TOPMOST "U moet beheerder zijn van het systeem om deze installatie uit te kunnen voeren. U bent: $R0"
Abort
AdminCheckEnd:
2)
Function .onInit
!insertmacro ADMIN_CHECK
!insertmacro CHECK_MSDE
!insertmacro AFTERREBOOT
FunctionEnd
You are detecting the admin without checking the Windows version. Try put before "!insertmacro ADMIN_CHECK" this below:

!insertmacro WINVERSION

3)
What I see is that the DLL Winver has been put in my install dir.... Is this the default behaviour?
Plugins have to be in the plugins subdirectory of your NSIS folder.

I found that the behaviour is seen when I use reboot and start again via HKCU....Runonce.
When it all happens to fast it does not detect my admin rights. After that it takes one, two or more tries to detect I'm admin. So I get the feeling it's too soon to detect admin rights.

The plugin is in my own plugindir, but it seems to get copied at installtime into a directory I'm installing into, allthough the actual copying of files and thus installing happens in a msi and not in this nsis part of my installer. From this part of the installer I just do some checks and execute some programs.


Did you call WinVer using the WinVer::command syntax? Get the same UserInfo problem with other installer scripts?


Shouldn't you also be checking for Windows 95 as well as 98?


I call the winver in the standard way, it's just added via
!addplugindir. The problem with userinfo is not in every installer, but I have to say I saw some other problems in other installers when started via the runonce registry key. Maybe it's best to build in some sleep? or is there a way to verify that the computer has finished starting up, finsished starting up services?

Win 95 is not supported by parts of my app, so not testing for it means nobody should be able to install it, which is no problem.


You can simply put the entry in the HKLM RunOnce key where you're sure that the user executing the installer will be admin. This will require to check ahead ahead with the program that adds the RunOnce key. You can also simply check ahead and not add the RunOnce entry if the user doesn't have admin rights.