Windows Users, Detect & List
Author: RobGrant (talk, contrib) |
Requires
Sunjammer's GetParent function.
Description
I wrote this because I needed a way of incorporating a list of the users of a machine into an installer; there was an option to add them to a certain group and make them able to logon as a service within the installer. I listed them by simply listing the contents of the "Documents and Settings" folder, minus the obvious folders which weren't necessary.
Usage
Could be cleaned up, etc. Used like this:
Push $R0 Push $R1 Push $R2 Push $R3 Call getUsers !insertmacro MUI_INSTALLOPTIONS_WRITE "guidialog.ini" "Field 2" "ListItems" "$R3" Pop $R3 Pop $R2 Pop $R1 Pop $R0
The output is a "|" separated list of users (e.g. rgrant|jworcester|bgates|smcnealy) in $R3
There is a possible issue with this method. If a user account has been renamed after it has been in use for a while it will retain the same folder name under Documents and Settings. Also if used with a domain, you could get different anomalies. This probably is not the best way to go about getting user names.
The Function
Function getUsers StrCpy $R3 "" Push "$PROFILE" Call GetParent Pop $R2 StrCpy $R2 "$R2" FindFirst $R0 $R1 "$R2\*" StrCmp $R1 "" findend 0 findloop: IfFileExists "$R2\$R1\*.*" 0 notDir StrCmp $R1 "." notDir StrCmp $R1 ".." notDir StrCmp $R1 "All Users" notDir StrCmp $R1 "Default User" notDir StrCpy $R3 "$R3|$R1" notDir: FindNext $R0 $R1 StrCmp $R1 "" findend 0 Goto findloop findend: FindClose $R0 ;MessageBox MB_OK "$R3" FunctionEnd