Ok, I'm a new at this so please bear with me. What I'm trying to accomplish is to scan each PC on our domain and find out whether or not their "My Documents" folder points to a network share. In short, I need this script to navigate to the "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\User Shell Folders" key and then read the value data in the "Personal" string and dump this to a text file. Below is the vbs I've found on the web and modified to fit my needs but my problem is, it doesn't seem to output when I tell it to scan the entire domain. If I, on the other hand, just tell it to scan my own local machine, it works like a charm.
Any suggestions?
' Declare the constants
Const HKCU = &H80000001 ' HKEY_CURRENT_USER
Const REG_SZ = 1 ' String value in registry (Not DWORD)
Const ForReading = 1
Const ForWriting = 2
' Set File objects...
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objDictionary2 = CreateObject("Scripting.Dictionary")
' Set string variables
strDomain = "EMPIRE" ' Your Domain
strPCsFile = "DomainPCs.txt"
strPath = "C:\logs\" ' Create this folder
strWorkstationID = "C:\logs\WorkstationID.txt"
If objFSO.FolderExists(strPath) Then
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
Else
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
WScript.Echo "Please create folder: then click OK."
End If
' Get list of domain PCs – Using above variables.
strMbox = MsgBox("Would you like info for entire domain: EMPIRE ?",3,"Hostname")
'an answer of yes will return a value of 6, causing script to collect domain PC info
If strMbox = 6 Then
Set objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)
Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not work
objDomain.Filter = Array("Computer")
For Each pcObject In objDomain
objPCTXTFile.WriteLine pcObject.Name
Next
objPCTXTFile.close
Else
'an answer of no will prompt user to input name of computer to scan and create PC file
strHost = InputBox("Enter the computer you wish to get Workstation ID","Hostname"," ")
Set strFile = objfso.CreateTextFile(strPath & strPCsFile, True)
strFile.WriteLine(strHost)
strFile.Close
End If
' Read list of computers from strPCsFile into objDictionary
Set readPCFile = objFSO.OpenTextFile(strPath & strPCsFile, ForReading)
i = 0
Do Until readPCFile.AtEndOfStream
strNextLine = readPCFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
readPCFile.Close
' Run the procedure defined in the Sub routine GetWorkstationID()
For each DomainPC in objDictionary
strComputer = objDictionary.Item(DomainPC)
GetWorkstationID()
Next
Set objFilesystem = Nothing
WScript.echo "Finished Scanning Network check : " & strPath
objFSO.DeleteFile(strWorkstationID)
objFSO.DeleteFile(strPath & strPCsFile)
Sub GetWorkstationID()
On Error Resume next
' WMI connection to the operating system note StdRegProv
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
If Err <> "0" Then
Exit Sub
End If
' Registry paths which hold the WorkstationID information.
unKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer \User Shell Folders\"
unValueName = ("Personal")
' Enumerate Registry subkey paths for WorkstationID.
'objReg.EnumKey HKCU, unKeyPath
Set objTextFile1 = objFSO.OpenTextFile(strWorkstationID, ForWriting,True)
'For Each Subkey in arrSubKeys
objTextFile1.WriteLine (unKeyPath & (Enter))
'Next
' Read Registry info stored in the strWorkstationID file
Set objTextFile3 = objFSO.OpenTextFile(strWorkstationID, ForReading)
'pipe the WorkstationID paths from the WorkstationID.txt file into a second dictionary
i = 0
Do Until objTextFile3.AtEndOfStream
strNextLine = objTextFile3.Readline
objDictionary2.Add i, strNextLine
i = i + 1
Loop
' These paths are used in the filenames you see in the strPath
pcName = "SYSTEM\CurrentControlSet\Control\ComputerName\Acti veComputerName\"
pcNameValueName = "ComputerName"
userPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"
userValueName = "DefaultUserName"
objReg.GetStringValue HKLM,pcName,pcNameValueName,pcValue
objReg.GetStringValue HKLM,userPath,userValueName,userValue
' Build up the filename found in the strPath
strFileName = UserValue & "_" & "On" & "_" & PCValue & "_" & "Workstation ID" _
& year(date()) & right("0" & month(date()),2) _
& right("0" & day(date()),2) & ".txt"
' Write each PC's software info file...
Set objTextFile2 = objFSO.OpenTextFile(strPath & strFileName, ForWriting, True)
' Writing info to the corresponding Software info file...
objTextFile2.WriteLine(vbCRLF & "==============================" & vbCRLF & _
"Current Workstation ID " & vbCRLF & Time & vbCRLF & Date _
& vbCRLF & "ID for:" & "" & userValue & vbCRLF & "On System:" _
& "" & pcValue & vbCRLF & "----------------------------------------" & vbCRLF)
' First enumeration also clean up if error exists (Second enumaration omitted)
For Each objItem in objDictionary2
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer \User Shell Folders\"
objReg.GetstringValue HKCU ,strKeyPath, unValueName, strValue
objTextFile2.WriteLine (strValue)
If Err Then
objDictionary2.Remove(objItem)
End If
Next
End Sub
wscript.Quit
Any suggestions?
' Declare the constants
Const HKCU = &H80000001 ' HKEY_CURRENT_USER
Const REG_SZ = 1 ' String value in registry (Not DWORD)
Const ForReading = 1
Const ForWriting = 2
' Set File objects...
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objDictionary2 = CreateObject("Scripting.Dictionary")
' Set string variables
strDomain = "EMPIRE" ' Your Domain
strPCsFile = "DomainPCs.txt"
strPath = "C:\logs\" ' Create this folder
strWorkstationID = "C:\logs\WorkstationID.txt"
If objFSO.FolderExists(strPath) Then
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
Else
Wscript.Echo "This program will collect Workstation ID on remote compter(s)"
WScript.Echo "Please create folder: then click OK."
End If
' Get list of domain PCs – Using above variables.
strMbox = MsgBox("Would you like info for entire domain: EMPIRE ?",3,"Hostname")
'an answer of yes will return a value of 6, causing script to collect domain PC info
If strMbox = 6 Then
Set objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)
Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not work
objDomain.Filter = Array("Computer")
For Each pcObject In objDomain
objPCTXTFile.WriteLine pcObject.Name
Next
objPCTXTFile.close
Else
'an answer of no will prompt user to input name of computer to scan and create PC file
strHost = InputBox("Enter the computer you wish to get Workstation ID","Hostname"," ")
Set strFile = objfso.CreateTextFile(strPath & strPCsFile, True)
strFile.WriteLine(strHost)
strFile.Close
End If
' Read list of computers from strPCsFile into objDictionary
Set readPCFile = objFSO.OpenTextFile(strPath & strPCsFile, ForReading)
i = 0
Do Until readPCFile.AtEndOfStream
strNextLine = readPCFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
readPCFile.Close
' Run the procedure defined in the Sub routine GetWorkstationID()
For each DomainPC in objDictionary
strComputer = objDictionary.Item(DomainPC)
GetWorkstationID()
Next
Set objFilesystem = Nothing
WScript.echo "Finished Scanning Network check : " & strPath
objFSO.DeleteFile(strWorkstationID)
objFSO.DeleteFile(strPath & strPCsFile)
Sub GetWorkstationID()
On Error Resume next
' WMI connection to the operating system note StdRegProv
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
If Err <> "0" Then
Exit Sub
End If
' Registry paths which hold the WorkstationID information.
unKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer \User Shell Folders\"
unValueName = ("Personal")
' Enumerate Registry subkey paths for WorkstationID.
'objReg.EnumKey HKCU, unKeyPath
Set objTextFile1 = objFSO.OpenTextFile(strWorkstationID, ForWriting,True)
'For Each Subkey in arrSubKeys
objTextFile1.WriteLine (unKeyPath & (Enter))
'Next
' Read Registry info stored in the strWorkstationID file
Set objTextFile3 = objFSO.OpenTextFile(strWorkstationID, ForReading)
'pipe the WorkstationID paths from the WorkstationID.txt file into a second dictionary
i = 0
Do Until objTextFile3.AtEndOfStream
strNextLine = objTextFile3.Readline
objDictionary2.Add i, strNextLine
i = i + 1
Loop
' These paths are used in the filenames you see in the strPath
pcName = "SYSTEM\CurrentControlSet\Control\ComputerName\Acti veComputerName\"
pcNameValueName = "ComputerName"
userPath = "Software\Microsoft\Windows NT\CurrentVersion\Winlogon\"
userValueName = "DefaultUserName"
objReg.GetStringValue HKLM,pcName,pcNameValueName,pcValue
objReg.GetStringValue HKLM,userPath,userValueName,userValue
' Build up the filename found in the strPath
strFileName = UserValue & "_" & "On" & "_" & PCValue & "_" & "Workstation ID" _
& year(date()) & right("0" & month(date()),2) _
& right("0" & day(date()),2) & ".txt"
' Write each PC's software info file...
Set objTextFile2 = objFSO.OpenTextFile(strPath & strFileName, ForWriting, True)
' Writing info to the corresponding Software info file...
objTextFile2.WriteLine(vbCRLF & "==============================" & vbCRLF & _
"Current Workstation ID " & vbCRLF & Time & vbCRLF & Date _
& vbCRLF & "ID for:" & "" & userValue & vbCRLF & "On System:" _
& "" & pcValue & vbCRLF & "----------------------------------------" & vbCRLF)
' First enumeration also clean up if error exists (Second enumaration omitted)
For Each objItem in objDictionary2
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer \User Shell Folders\"
objReg.GetstringValue HKCU ,strKeyPath, unValueName, strValue
objTextFile2.WriteLine (strValue)
If Err Then
objDictionary2.Remove(objItem)
End If
Next
End Sub
wscript.Quit