The script:

On Error Resume Next
Const HKCU = &H80000001 ' HKEY_CURRENT_USER
Const ForReading = 1
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
& _
"ZoneMap\Domains"
strAOLKeyPath = "\aol.com"
strNapsterKeyPath = "\napster.com"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = _
objFSO.OpenTextFile("C:\Documents and Settings\MyUser\Desktop\computers.TXT")
strComputers = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strComputers, vbCrLf)
Set objShell = CreateObject("WScript.Shell")
For Each strComputer In arrComputers
strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
Set objExecObject = objShell.Exec(strCommand)
strText = objExecObject.StdOut.ReadAll
If Instr(strText, "Reply") > 0 Then
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
Set objReg = GetObject("winmgmts:\\" & strComputer & _
"\root\default:StdRegProv")
WScript.Echo("For workstation " & strComputer & ":")
objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
End If
objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
End If
Else
WScript.Echo strComputer & " could not be reached."
End If
Next

The problem:

Several of the machines return error 70, helpfully defined as "Permission
denied." Three of them return error 424, mysteriously defined as "Object
required."

I'm running the script while logged into a server as a domain admin, and
said server can ping every machine, so connectivity is not an issue. Can
anyone explain the above errors and how I might fix them? The script ran
against most of the machines just fine, removing the registry keys I wanted
removed.

Thanks in advance!

Re: Errors 70 & 424? by Richard

Richard
Thu Jul 26 19:38:10 CDT 2007

KHauer wrote:

> The script:
>
> On Error Resume Next
> Const HKCU = &H80000001 ' HKEY_CURRENT_USER
> Const ForReading = 1
> strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet
> Settings\"
> & _
> "ZoneMap\Domains"
> strAOLKeyPath = "\aol.com"
> strNapsterKeyPath = "\napster.com"
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = _
> objFSO.OpenTextFile("C:\Documents and
> Settings\MyUser\Desktop\computers.TXT")
> strComputers = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strComputers, vbCrLf)
> Set objShell = CreateObject("WScript.Shell")
> For Each strComputer In arrComputers
> strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
> Set objExecObject = objShell.Exec(strCommand)
> strText = objExecObject.StdOut.ReadAll
> If Instr(strText, "Reply") > 0 Then
> Set objLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
> Set objReg = GetObject("winmgmts:\\" & strComputer & _
> "\root\default:StdRegProv")
> WScript.Echo("For workstation " & strComputer & ":")
> objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
> End If
> objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
> End If
> Else
> WScript.Echo strComputer & " could not be reached."
> End If
> Next
>
> The problem:
>
> Several of the machines return error 70, helpfully defined as "Permission
> denied." Three of them return error 424, mysteriously defined as "Object
> required."
>
> I'm running the script while logged into a server as a domain admin, and
> said server can ping every machine, so connectivity is not an issue. Can
> anyone explain the above errors and how I might fix them? The script ran
> against most of the machines just fine, removing the registry keys I
> wanted
> removed.
>
> Thanks in advance!

My guess is that an error occurred earlier, but was ignored because you use
"On Error Resume Next". For example, the Set objReg statement can raise on
error on certain computers. The object objReg may the missing object, or you
may lack permission to connect to a computer. I would remove the first "On
Error Resume Next" statement and replace the following snippet from your
code:

Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
Set objReg = GetObject("winmgmts:\\" & strComputer & _
"\root\default:StdRegProv")
WScript.Echo("For workstation " & strComputer & ":")
objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & "
occurred.")
End If
objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & "
occurred.")
End If

with this:

Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\"
_
& strComputer & "\root\default:StdRegProv")
WScript.Echo("For workstation " & strComputer & ":")
' Trap possible error.
On Error Resume Next
objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & "
occurred.")
' Clear the error so we can tell if the next statement raises an
error.
Err.Clear
End If
objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
If Err.Number = 0 Then
WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
" if it existed.")
Else
WScript.Echo(vbTab & "Error number " & Err.Number & "
occurred.")
End If
' Restore normal error handling. This also clears any error
condition.
On Error GoTo 0

Note that the objLocator and objConn object references are not needed. The
extra parameters used when connecting to the computers with WMI
(impersonationLevel and authenticationLevel) work with more OS's. If there
is an error connecting, you will get an error message and have a better
chance troubleshooting as you will know the line number. I trap the possible
error raised when you delete the registry keys, but restore normal error
handling so any other errors can be found and are not masked. The above has
not been tested. I hope this helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Errors 70 & 424? by KHauer

KHauer
Fri Jul 27 10:34:00 CDT 2007

Thank you Richard, for your help. I implemented your suggested changes, and
when testing the script I get the following error:

C:\Documents and Settings\ISkh\Desktop\delSubKeys.VBS(47, 3) Microsoft
VBScript
runtime error: Permission denied: 'GetObject'

Line 47 is the following line:

Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
& strComputer & "\root\default:StdRegProv")

Any thoughts as to why I'd get the permission denied error there?
"Richard Mueller [MVP]" wrote:

> KHauer wrote:
>
> > The script:
> >
> > On Error Resume Next
> > Const HKCU = &H80000001 ' HKEY_CURRENT_USER
> > Const ForReading = 1
> > strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet
> > Settings\"
> > & _
> > "ZoneMap\Domains"
> > strAOLKeyPath = "\aol.com"
> > strNapsterKeyPath = "\napster.com"
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTextFile = _
> > objFSO.OpenTextFile("C:\Documents and
> > Settings\MyUser\Desktop\computers.TXT")
> > strComputers = objTextFile.ReadAll
> > objTextFile.Close
> > arrComputers = Split(strComputers, vbCrLf)
> > Set objShell = CreateObject("WScript.Shell")
> > For Each strComputer In arrComputers
> > strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
> > Set objExecObject = objShell.Exec(strCommand)
> > strText = objExecObject.StdOut.ReadAll
> > If Instr(strText, "Reply") > 0 Then
> > Set objLocator = CreateObject("WbemScripting.SWbemLocator")
> > Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
> > Set objReg = GetObject("winmgmts:\\" & strComputer & _
> > "\root\default:StdRegProv")
> > WScript.Echo("For workstation " & strComputer & ":")
> > objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
> > If Err.Number = 0 Then
> > WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
> > " if it existed.")
> > Else
> > WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
> > End If
> > objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
> > If Err.Number = 0 Then
> > WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
> > " if it existed.")
> > Else
> > WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
> > End If
> > Else
> > WScript.Echo strComputer & " could not be reached."
> > End If
> > Next
> >
> > The problem:
> >
> > Several of the machines return error 70, helpfully defined as "Permission
> > denied." Three of them return error 424, mysteriously defined as "Object
> > required."
> >
> > I'm running the script while logged into a server as a domain admin, and
> > said server can ping every machine, so connectivity is not an issue. Can
> > anyone explain the above errors and how I might fix them? The script ran
> > against most of the machines just fine, removing the registry keys I
> > wanted
> > removed.
> >
> > Thanks in advance!
>
> My guess is that an error occurred earlier, but was ignored because you use
> "On Error Resume Next". For example, the Set objReg statement can raise on
> error on certain computers. The object objReg may the missing object, or you
> may lack permission to connect to a computer. I would remove the first "On
> Error Resume Next" statement and replace the following snippet from your
> code:
>
> Set objLocator = CreateObject("WbemScripting.SWbemLocator")
> Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
> Set objReg = GetObject("winmgmts:\\" & strComputer & _
> "\root\default:StdRegProv")
> WScript.Echo("For workstation " & strComputer & ":")
> objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & "
> occurred.")
> End If
> objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & "
> occurred.")
> End If
>
> with this:
>
> Set objReg = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\"
> _
> & strComputer & "\root\default:StdRegProv")
> WScript.Echo("For workstation " & strComputer & ":")
> ' Trap possible error.
> On Error Resume Next
> objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & "
> occurred.")
> ' Clear the error so we can tell if the next statement raises an
> error.
> Err.Clear
> End If
> objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
> If Err.Number = 0 Then
> WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
> " if it existed.")
> Else
> WScript.Echo(vbTab & "Error number " & Err.Number & "
> occurred.")
> End If
> ' Restore normal error handling. This also clears any error
> condition.
> On Error GoTo 0
>
> Note that the objLocator and objConn object references are not needed. The
> extra parameters used when connecting to the computers with WMI
> (impersonationLevel and authenticationLevel) work with more OS's. If there
> is an error connecting, you will get an error message and have a better
> chance troubleshooting as you will know the line number. I trap the possible
> error raised when you delete the registry keys, but restore normal error
> handling so any other errors can be found and are not masked. The above has
> not been tested. I hope this helps.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>

Re: Errors 70 & 424? by Richard

Richard
Fri Jul 27 11:42:22 CDT 2007

You must have administrator privileges on the computer to read the registry.
The error message sounds like you do not.

By default, the group "Domain Admins" is added to the local Adminstrators
group when the computer is joined to the domain. If your account is a member
of "Domain Admins", you should have administrator privileges on the
computer. Is it possible that "Domain Admins" has been removed from the
local Administrators group on the computers with the problem? Other less
likely causes could be firewall issues or DCOM disabled on the computer.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

"KHauer" <KHauer@discussions.microsoft.com> wrote in message
news:104A2126-C5AC-4436-A97B-F23C060DA3E9@microsoft.com...
> Thank you Richard, for your help. I implemented your suggested changes,
> and
> when testing the script I get the following error:
>
> C:\Documents and Settings\ISkh\Desktop\delSubKeys.VBS(47, 3) Microsoft
> VBScript
> runtime error: Permission denied: 'GetObject'
>
> Line 47 is the following line:
>
> Set objReg = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\" _
> & strComputer & "\root\default:StdRegProv")
>
> Any thoughts as to why I'd get the permission denied error there?
> "Richard Mueller [MVP]" wrote:
>
>> KHauer wrote:
>>
>> > The script:
>> >
>> > On Error Resume Next
>> > Const HKCU = &H80000001 ' HKEY_CURRENT_USER
>> > Const ForReading = 1
>> > strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet
>> > Settings\"
>> > & _
>> > "ZoneMap\Domains"
>> > strAOLKeyPath = "\aol.com"
>> > strNapsterKeyPath = "\napster.com"
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objTextFile = _
>> > objFSO.OpenTextFile("C:\Documents and
>> > Settings\MyUser\Desktop\computers.TXT")
>> > strComputers = objTextFile.ReadAll
>> > objTextFile.Close
>> > arrComputers = Split(strComputers, vbCrLf)
>> > Set objShell = CreateObject("WScript.Shell")
>> > For Each strComputer In arrComputers
>> > strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer
>> > Set objExecObject = objShell.Exec(strCommand)
>> > strText = objExecObject.StdOut.ReadAll
>> > If Instr(strText, "Reply") > 0 Then
>> > Set objLocator = CreateObject("WbemScripting.SWbemLocator")
>> > Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
>> > Set objReg = GetObject("winmgmts:\\" & strComputer & _
>> > "\root\default:StdRegProv")
>> > WScript.Echo("For workstation " & strComputer & ":")
>> > objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
>> > If Err.Number = 0 Then
>> > WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
>> > " if it existed.")
>> > Else
>> > WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
>> > End If
>> > objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
>> > If Err.Number = 0 Then
>> > WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
>> > " if it existed.")
>> > Else
>> > WScript.Echo(vbTab & "Error number " & Err.Number & " occurred.")
>> > End If
>> > Else
>> > WScript.Echo strComputer & " could not be reached."
>> > End If
>> > Next
>> >
>> > The problem:
>> >
>> > Several of the machines return error 70, helpfully defined as
>> > "Permission
>> > denied." Three of them return error 424, mysteriously defined as
>> > "Object
>> > required."
>> >
>> > I'm running the script while logged into a server as a domain admin,
>> > and
>> > said server can ping every machine, so connectivity is not an issue.
>> > Can
>> > anyone explain the above errors and how I might fix them? The script
>> > ran
>> > against most of the machines just fine, removing the registry keys I
>> > wanted
>> > removed.
>> >
>> > Thanks in advance!
>>
>> My guess is that an error occurred earlier, but was ignored because you
>> use
>> "On Error Resume Next". For example, the Set objReg statement can raise
>> on
>> error on certain computers. The object objReg may the missing object, or
>> you
>> may lack permission to connect to a computer. I would remove the first
>> "On
>> Error Resume Next" statement and replace the following snippet from your
>> code:
>>
>> Set objLocator = CreateObject("WbemScripting.SWbemLocator")
>> Set objConn = objLocator.ConnectServer(strComputer, "root\cimv2")
>> Set objReg = GetObject("winmgmts:\\" & strComputer & _
>> "\root\default:StdRegProv")
>> WScript.Echo("For workstation " & strComputer & ":")
>> objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
>> If Err.Number = 0 Then
>> WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
>> " if it existed.")
>> Else
>> WScript.Echo(vbTab & "Error number " & Err.Number & "
>> occurred.")
>> End If
>> objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
>> If Err.Number = 0 Then
>> WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
>> " if it existed.")
>> Else
>> WScript.Echo(vbTab & "Error number " & Err.Number & "
>> occurred.")
>> End If
>>
>> with this:
>>
>> Set objReg = GetObject("winmgmts:" _
>> &
>> "{impersonationLevel=impersonate,authenticationLevel=Pkt}!\\"
>> _
>> & strComputer & "\root\default:StdRegProv")
>> WScript.Echo("For workstation " & strComputer & ":")
>> ' Trap possible error.
>> On Error Resume Next
>> objReg.DeleteKey HKCU, strKeyPath & strAOLKeyPath
>> If Err.Number = 0 Then
>> WScript.Echo(vbTab & "Deleted key: " & strAOLKeyPath & _
>> " if it existed.")
>> Else
>> WScript.Echo(vbTab & "Error number " & Err.Number & "
>> occurred.")
>> ' Clear the error so we can tell if the next statement raises
>> an
>> error.
>> Err.Clear
>> End If
>> objReg.DeleteKey HKCU, strKeyPath & strNapsterKeyPath
>> If Err.Number = 0 Then
>> WScript.Echo(vbTab & "Deleted key: " & strNapsterKeyPath & _
>> " if it existed.")
>> Else
>> WScript.Echo(vbTab & "Error number " & Err.Number & "
>> occurred.")
>> End If
>> ' Restore normal error handling. This also clears any error
>> condition.
>> On Error GoTo 0
>>
>> Note that the objLocator and objConn object references are not needed.
>> The
>> extra parameters used when connecting to the computers with WMI
>> (impersonationLevel and authenticationLevel) work with more OS's. If
>> there
>> is an error connecting, you will get an error message and have a better
>> chance troubleshooting as you will know the line number. I trap the
>> possible
>> error raised when you delete the registry keys, but restore normal error
>> handling so any other errors can be found and are not masked. The above
>> has
>> not been tested. I hope this helps.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>