Here is some code that will pull a list from AD, ping verify the PC, enum the HKU hives and then read from the HKU hive. All the code has been *borrowed* from this board and credit may not have been given to the original author.
Code:
break on
$ = RedirectOutput('C:\UserNameReport.txt')
$objConnection = CreateObject("ADODB.Connection")
$objCommand = CreateObject("ADODB.Command")
$objConnection.Provider = "ADsDSOObject"
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection
$objCommand.CommandText =
"SELECT Name FROM "
+ "'LDAP://OU=Computers,OU=yada,OU=yada,dc=domain,dc=local'"
+ " WHERE objectCategory='computer'"
$objCommand.Properties("Page Size").Value = 100
$objCommand.Properties("Search Scope").Value = 2
$objCommand.Properties("Cache Results").Value = (not 1)
$objRecordSet = $objCommand.Execute()
$objRecordSet.MoveFirst
while not $objRecordSet.EOF
$curComputer = $objRecordSet.Fields("Name").Value
DoX($curComputer)
$objRecordSet.MoveNext
Loop
$ = RedirectOutput('')
"Done" ?
Function DoX($Computer)
If Ping($Computer)
Dim $BaseKey, $Key, $UserInfo
$BaseKey = '\\' + $Computer + '\HKEY_USERS'
For Each $Key In fEnumKey('',$BaseKey)
If Len($Key) = 44
Select
Case KeyExist($BaseKey + '\' + $Key + '\Software\Microsoft\Office\11.0\Common\UserInfo')
$UserInfo = ReadValue($BaseKey + '\' + $Key + '\Software\Microsoft\Office\11.0\Common\UserInfo', 'UserName')
Case KeyExist($BaseKey + '\' + $Key + '\Software\Microsoft\Office\10.0\Common\UserInfo')
$UserInfo = ReadValue($BaseKey + '\' + $Key + '\Software\Microsoft\Office\10.0\Common\UserInfo', 'UserName')
Case KeyExist($BaseKey + '\' + $Key + '\Software\Microsoft\Office\9.0\Common\UserInfo')
$UserInfo = ReadValue($BaseKey + '\' + $Key + '\Software\Microsoft\Office\9.0\Common\UserInfo', 'UserName')
Case 1
EndSelect
If Len($UserInfo) >4
$Computer + ' = [' + UserName($UserInfo) + ']' ?
EndIf
EndIf
Next
EndIf
EndFunction
;===================
Function UserName($UserInfo)
For $Pos = 1 to Len($UserInfo) step 4
$UserName = $UserName + Chr(Hex2Dec(SubStr($UserInfo,$pos,2)))
Next
EndFunction
;===================
;;FUNCTION Hex2Dec()
;;
;;ACTION Convert a Hex string to a decimal number
;;
;;AUTHOR Glenn Barnas / FRIT-EROC
;;
;;SYNTAX Hex2Dec(HexValue)
;;
;;PARAMETERS HexValue - REQUIRED - Hex value to be converted to Decimal
;;
;;REMARKS Converts hex strings to decimal values. Currently set to
;; use a max of 40 bits (10 hex digits), which is a maximum
;; decimal value of of 1,099,511,627,775 (that's 1 Trillion)
;;
;;RETURNS Decimal value
;;
;;DEPENDENCIES Kix 4.1+
;;
;;TESTED WITH WinNT, Win2K, WinXP, Win2K3
;;
;;EXAMPLES $DecVal = Hex2Dec('3f79cb00')
;
; Convert Hex-number to string representation of Decimal value
Function Hex2Dec($Hex)
; Define the limit
; 40 bits for max value of 549,755,813,888 (1023G or 1023 Billion!)
Dim $MaxBits
$MaxBits = 40
Dim $HexArr, $BinArr, $P, $Ch, $nb, $BinStr, $V, $D
Dim $DecArr[$MaxBits]
$HexArr = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
; Note that the bits in each element are BACKWARDS! - This allows easier L-R LSB->MSB processing
$BinArr = '0000','1000','0100','1100','0010','1010','0110','1110','0001','1001','0101','1101',
'0011','1011','0111','1111'
; Process check - can't handle more than MaxBits/4 hex digits
If Len($Hex) > ($MaxBits / 4)
$Hex2Dec = 0
Exit 87
EndIF
; Init the Decimal Array
$DecArr[1] = 1.0
For $P = 2 to $MaxBits
$DecArr[$P] = $DecArr[$P - 1] * 2
Next
; Convert Hex-number to binary string
$BinStr = ''
For $P = 1 To Len($Hex)
$Ch = SubStr($Hex, $P, 1)
$nb = AScan($HexArr, $Ch)
If $nb < 0 ; Error in hex-string, contains non-valid characters
'invalid hex-string' ?
$BinStr = '0'
Exit 87
EndIf
; Add the string value for the current hex digit
$BinStr = $BinArr[$nb] + $BinStr
Next
; Convert binary string to a decimal number
$Hex2Dec = 0.0
For $P = 1 to Len($BinStr)
$Ch = SubStr($BinStr, $P, 1)
If $Ch = 1
$Hex2Dec = 0.0 + $Hex2Dec + CDbl($DecArr[$P])
EndIf
Next
exit 0
EndFunction
;===================
Function Ping($PC)
Dim $PC
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @error
EndFunction
;===================
;AUTHOR Howard A. Bullock (habullock@comcast.net)
;
;ACTION Enumerates registries keys on the specified computer.
;
;SYNTAX fEnumKey($Computer, $Key)
;
;PARAMETERS $Computer (Required) - String value
; $Key (Required) - String value
;
;REMARKS Do not prefix the computer name with "\\"'s. Can serve as a
; direct replacement for EnumKey().
;
;RETURNS Array of keys names.
;
;DEPENDENCIES KiXtart 4.02,
;
;EXAMPLES fEnumKey("", "HKEY_USERS")
; fEnumKey("Remote1", "HKEY_USERS")
;
Function fEnumKey($Server, $Key)
Dim $Index, $Error, $x
$Index = 0
Dim $KeyName[$Index]
If $Server <> ""
$Key = "\\" + $Server + "\" + $Key
Endif
If KeyExist($Key)
Do
$x = ENUMKEY($Key, $Index)
$Error = @Error
If NOT $Error and $Index > Ubound($KeyName)
ReDim PRESERVE $KeyName[$Index]
Endif
If NOT $Error
$KeyName[$Index] = $x
$Index = $Index + 1
Endif
Until $Error
Else
$KeyName[0] = ""
Exit 2
Endif
$fEnumKey = $KeyName
Exit 0
Endfunction