Lack of sleep appears to be taking it's toll... I am attempting to enumerate the computers on the domain, loop through them to see if they have a specific registry KEY(not a value), and then document if the key was or was not there and if the computer was offline and not checked. The ping part, in testing, is showing my remote test box as offline. However, the box I am running the script from shows as online but it says the registry key is not present even though it is. Any help is greatly appreciated!!! There is tons of stuff out there regarding verifying registry values but not keys. Many often mistakenly state registry keys but then in the script they actually verify the existence of the registry value. Additionally, my report is giving duplicate entries. I have tried putting the write action in different places but I can't seem to grasp the output concept via this implementation... Also, without looping through all the boxes multiple times, is there a way to create multiple output files based on the conditions? My current solution is to code the presence of the key as 0 or 1 and simply label the skipped boxes as "offline". This can be sorted and refined manually or via another additional script but I would like to avoid if possible. My ideal output would be different files like this; CompWithkey.txt, CompWithOutkey.txt, CompNotVerified.txt
Thanks
Thanks
Script said:On Error Resume Next
strREG = "SOFTWARE"
strKey = "ODBC"
strReportPath = "InstallStatus.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("Wscript.Shell")
Set objFile = objFSO.OpenTextFile(strReportPath, 8, True, 0)
Set oRootDSE = GetObject("LDAP://rootDSE")
strDom = oRootDSE.Get("DefaultNamingContext")
' available categories = computer, user, printqueue, group
qQuery = "<LDAP://" & strDom & ">;" & "(objectCategory=computer)" & _
";name;subtree"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Open "Provider=ADsDSOObject;"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = qQuery
Set objRecordSet = objCommand.Execute
If (Err.Number <> 0) Then
On Error GoTo 0
WScript.Echo "File " & strFilePath & " cannot be created"
Set objFSO = Nothing
WScript.Quit
End If
'Header line of report
Report = "Computer Name, " & "Status Code (0=Not Installed, 1=Installed)" & VBNewLine
objFile.Write Report
Do Until objRecordSet.EOF
strPingStatus = PingStatus(objRecordSet.Fields("name"))
If strPingStatus = "Success" Then
CheckREG objRecordSet.Fields("name"),strREG,strKey
Else
Report = objRecordSet.Fields("name") & ", offline"
'Report = Report & CheckREG(objRecordSet.Fields("name"),strREG,strKey)
objFile.Write Report
End If
'objFile.Write Report
objrecordset.MoveNext
Loop
adoRecordset.Close
WSHShell.Run "InstallStatus.txt"
Function CheckREG(strComputer, strKeyPath, strRegKey)
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
Const HKLM = &H80000002
objReg.EnumKey HKLM, strKeyPath, arrSubKeys
For Each Subkey In arrSubKeys
If InStr(subkey, strRegKey) > 0 Then
'Key exists
Report = strComputer & ", 1" & VBNewLine
Else
Report = strComputer & ", 0" & VBNewLine
End If
Next
'Report = Report & InStr(subkey, strRegKey,1) & VBNewLine
'Report = Report & strcomputer & ", " & strKeyPath & ", " & strRegKey & VBNewLine
objFile.Write Report
'CheckREG = Report
End Function
Function PingStatus(strWorkstation)
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strWorkstation & "\root\cimv2")
Set colPings = objWMIService.ExecQuery _
( "SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'" )
For Each objPing In colPings
Select Case objPing.StatusCode
Case 0 PingStatus = "Success"
Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
Case 11004 PingStatus = "Status code 11004 - Destination Protocol Unreachable"
Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
Case 11006 PingStatus = "Status code 11006 - No Resources"
Case 11007 PingStatus = "Status code 11007 - Bad Option"
Case 11008 PingStatus = "Status code 11008 - Hardware Error"
Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
Case 11011 PingStatus = "Status code 11011 - Bad Request"
Case 11012 PingStatus = "Status code 11012 - Bad Route"
Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
Case 11014 PingStatus = "Status code 11014 - TimeToLive Expired Reassembly"
Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
Case 11016 PingStatus = "Status code 11016 - Source Quench"
Case 11017 PingStatus = "Status code 11017 - Option Too Big"
Case 11018 PingStatus = "Status code 11018 - Bad Destination"
Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
Case 11050 PingStatus = "Status code 11050 - General Failure"
Case Else PingStatus = "Status code " & objPing.StatusCode & _
" - Unable to determine cause of failure."
End Select
Next
End Function