Skip to content
⌘ NSIS Forum Archive

Problem with UserInfo or StrCmp or with me.

4 posts

rmhost#

Problem with UserInfo or StrCmp or with me.

Hello,

After reading the documentation I tried to start experimenting with some of those examples that I found. Now base on the script that I experiment below, what I want to achieve is, if a user is not a member of Power User or Administrator group it will pop-up a message that says "User is just an ordinary user". Now when I try this script with a user that don't belong to Power User or Admin group, the message that pop-up is "Error! This DLL can't run under Windows 9x!".

Maybe I missed something here, why is it that my script didn't work?

Thanks!




Function .onInit
  Call TestFunction
  Pop $R0
  MessageBox MB_OK "$R0"
  Abort
FunctionEnd
Function TestFunction
  Push $R0
    ClearErrors
    UserInfo::GetName
    IfErrors Win9x
    Pop $0
    UserInfo::GetAccountType
    Pop $1
    StrCmp $1 "Admin" 0 +3
        Strcpy $R0 'User "$0" is in the Administrators group'
        Goto done
    StrCmp $1 "Power" 0 +3
        Strcpy $R0 'User "$0" is in the Power Users group'
        Goto done
      Strcpy $R0 'User "$0" is just an ordinary user'
    
;  StrCmp $1 "User" 0 +3
;        Strcpy $R0 'User "$0" is just a regular user'
;        Goto done
;    StrCmp $1 "Guest" 0 +3
;        Strcpy $R0 'User "$0" is a guest'
;        Goto done
;    Strcpy $R0 "Unknown error"
    Win9x:
        # This one means you don't need to care about admin or
        # not admin because Windows 9x doesn't either
        Strcpy $R0 "Error! This DLL can't run under Windows 9x!"
    done:
 Exch $R0
FunctionEnd 
rmhost#
btw I tried it on win2kpro. I'm confused with this portion. AFAIK this code:

StrCmp $1 "Admin" 0 +3
        Strcpy $R0 'User "$0" is in the Administrators group'
        Goto done
    StrCmp $1 "Power" 0 +3
        Strcpy $R0 'User "$0" is in the Power Users group'
        Goto done
    Strcpy $R0 'User "$0" is just an ordinary user' 

is similar to this: (I mean its logic)

if $1 == "Admin"
     $R0 = "administrator group"
     Goto done
else if $1 == "Power"
     $R0 = "Power User group"
     Goto done
else
     $R0 = "is an ordinary user" 
please correct me if Im wrong. Or maybe I missed something here.
kichik#
You're correct, but you forgot to jump to done after the last StrCpy which causes NSIS to continue and process Win9x and show the error message.