Please find a sample from a script I am working on to check every IP address in a 24 bit subnet and if it is a computer running windows remove certian registry keys.
The problem is some of the computers are returning an error desription of "Name redefined"??????
(Sample.vbs)
strSubNet="192.168.0."
Set objShell = CreateObject("Wscript.Shell"
On Error Resume Next
for i = 1 to 254
strIPAdd= StrSubNet & i
Set ObjScriptExec = objShell.Exec("ping -n 1 -w 20 " & StrIPAdd)
StrPingStdOut=LCase(ObjScriptExec.StdOut.ReadAll)
If InStr(StrPingStdOut, "reply from " & StrIPAdd) Then
Set WbemService = GetObject("winmgmts:\\" & strIPAdd )
if Err.Number <> 0 Then
wscript.echo StrIPAdd, err.description
err.clear
Else
Const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strIPAdd & "\root\default:StdRegProv"
strKeyPath1 = "SOFTWARE\Microsoft\MSLicensing\Store\LICENSE000"
strKeyPath1A = "SOFTWARE\Microsoft\MSLicensing\Store\LICENSE001"
strKeyPath2 = "SOFTWARE\Microsoft\MSLicensing\Store"
strKeyPath3 = "SOFTWARE\Microsoft\MSLicensing\HardwareID"
strKeyPath4 = "SOFTWARE\Microsoft\MSLicensing"
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath1
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath1a
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath2
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath3
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath4
Wscript.echo StrIPAdd, "completed sucessfully"
End If
Else
End If
Next
Sample Output from script as follows,
192.168.0.1 The remote server machine does not exist or is unavailable
192.168.0.12 completed sucessfully
192.168.0.13 completed sucessfully
192.168.0.14 The remote server machine does not exist or is unavailable
192.168.0.16 completed sucessfully
192.168.0.17 Name redefined
192.168.0.18 completed sucessfully
192.168.0.20 Name redefined
192.168.0.22 completed sucessfully
192.168.0.100 Name redefined
192.168.0.101 completed sucessfully
192.168.0.211 The remote server machine does not exist or is unavailable
192.168.0.212 The remote server machine does not exist or is unavailable
192.168.0.241 The remote server machine does not exist or is unavailable
I am only fairly new to VBscript and WMI and need help to debug this.
Thanks in advance,
Bretto.
The problem is some of the computers are returning an error desription of "Name redefined"??????
(Sample.vbs)
strSubNet="192.168.0."
Set objShell = CreateObject("Wscript.Shell"
On Error Resume Next
for i = 1 to 254
strIPAdd= StrSubNet & i
Set ObjScriptExec = objShell.Exec("ping -n 1 -w 20 " & StrIPAdd)
StrPingStdOut=LCase(ObjScriptExec.StdOut.ReadAll)
If InStr(StrPingStdOut, "reply from " & StrIPAdd) Then
Set WbemService = GetObject("winmgmts:\\" & strIPAdd )
if Err.Number <> 0 Then
wscript.echo StrIPAdd, err.description
err.clear
Else
Const HKEY_LOCAL_MACHINE = &H80000002
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strIPAdd & "\root\default:StdRegProv"
strKeyPath1 = "SOFTWARE\Microsoft\MSLicensing\Store\LICENSE000"
strKeyPath1A = "SOFTWARE\Microsoft\MSLicensing\Store\LICENSE001"
strKeyPath2 = "SOFTWARE\Microsoft\MSLicensing\Store"
strKeyPath3 = "SOFTWARE\Microsoft\MSLicensing\HardwareID"
strKeyPath4 = "SOFTWARE\Microsoft\MSLicensing"
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath1
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath1a
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath2
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath3
objReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath4
Wscript.echo StrIPAdd, "completed sucessfully"
End If
Else
End If
Next
Sample Output from script as follows,
192.168.0.1 The remote server machine does not exist or is unavailable
192.168.0.12 completed sucessfully
192.168.0.13 completed sucessfully
192.168.0.14 The remote server machine does not exist or is unavailable
192.168.0.16 completed sucessfully
192.168.0.17 Name redefined
192.168.0.18 completed sucessfully
192.168.0.20 Name redefined
192.168.0.22 completed sucessfully
192.168.0.100 Name redefined
192.168.0.101 completed sucessfully
192.168.0.211 The remote server machine does not exist or is unavailable
192.168.0.212 The remote server machine does not exist or is unavailable
192.168.0.241 The remote server machine does not exist or is unavailable
I am only fairly new to VBscript and WMI and need help to debug this.
Thanks in advance,
Bretto.