UserInfo.nsi 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. Name "UserInfo.dll test"
  2. OutFile UserInfo.exe
  3. RequestExecutionLevel Highest
  4. !define REALMSG "$\nOriginal non-restricted account type: $2"
  5. Section
  6. ClearErrors
  7. UserInfo::GetName
  8. IfErrors PluginFail
  9. Pop $0
  10. StrCmp $0 "" 0 +2 ; GetName can return a empty string on Win9x
  11. StrCpy $0 "?"
  12. UserInfo::GetAccountType
  13. Pop $1
  14. # GetOriginalAccountType will check the tokens of the original user of the
  15. # current thread/process. If the user tokens were elevated or limited for
  16. # this process, GetOriginalAccountType will return the non-restricted
  17. # account type.
  18. # On Vista with UAC, for example, this is not the same value when running
  19. # with `RequestExecutionLevel user`. GetOriginalAccountType will return
  20. # "admin" while GetAccountType will return "user".
  21. UserInfo::GetOriginalAccountType
  22. Pop $2
  23. StrCmp $1 "Admin" 0 +3 ; Note: Win9x always returns "Admin"
  24. MessageBox MB_OK 'User "$0" is in the Administrators group${REALMSG}'
  25. Goto done
  26. StrCmp $1 "Power" 0 +3
  27. MessageBox MB_OK 'User "$0" is in the Power Users group${REALMSG}'
  28. Goto done
  29. StrCmp $1 "User" 0 +3
  30. MessageBox MB_OK 'User "$0" is just a regular user${REALMSG}'
  31. Goto done
  32. StrCmp $1 "Guest" 0 +3
  33. MessageBox MB_OK 'User "$0" is a guest${REALMSG}'
  34. Goto done
  35. MessageBox MB_OK "Unknown error"
  36. Goto done
  37. PluginFail:
  38. MessageBox MB_OK "Error! Unable to call plug-in!"
  39. done:
  40. SectionEnd