HearSay
Fri Mar 30 07:06:05 CDT 2007
Thank you very much Richard
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:urRL59lcHHA.5044@TK2MSFTNGP05.phx.gbl...
>
> "Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
> message news:u42KpUlcHHA.1216@TK2MSFTNGP03.phx.gbl...
>>
>> "Anthony Jones" <Ant@yadayadayada.com> wrote in message
>> news:%23tPlJ1kcHHA.1340@TK2MSFTNGP04.phx.gbl...
>>>
>>> "HearSay" <hearsay@hotmail.com> wrote in message
>>> news:e4yt1ejcHHA.4888@TK2MSFTNGP06.phx.gbl...
>>>> My vbscript runs through a list of computers and performs a check. On
>>>> a
>>> few
>>>> computers I get the following
>>>>
>>>> Error: Permission denied: 'Get Object'
>>>> Code: 800A0046
>>>>
>>>> Errors on this: Set oRegistry =
>>>> GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer
>>>> &
>>>> "/root/default:StdRegProv")
>>>>
>>>> I have On Error Resume Next in my script, however, then this error is
>>>> encountered it is retaining the values from the last successful check.
>>>> I
>>>> need to be able to skip over this and not retain the previous value.
>>>>
>>>>
>>>
>>> Place this line before your GetObject line.
>>> Set oRegistry = Nothing
>>>
>>> Now if the GetObject fails oRegistry will remain nothing.
>>>
>>
>> Another option is to trap the error. This error is so common that I
>> always code similar to:
>> ===============
>> Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
>> & strComputer &
>> "/root/default:StdRegProv")
>>
>> On Error Resume Next
>> Set oRegistry = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\" _
>> & strComputer & "\root\default:StdRegProv")
>> If (Err.Number <> 0) Then
>> On Error GoTo 0
>> ' Error. Alert user, log, or whatever.
>> Else
>> On Error GoTo 0
>> ' Continue.
>> End If
>> ===========
>> I dislike leaving normal error handling disabled, as it causes problems
>> like yours that can be very difficult to troubleshoot. If something
>> unexpected goes wrong, I want to know about it. This error is raised if
>> the computer does not have WMI installed, the WMI service is not running,
>> WMI is corrupt, or you lack permissions.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab -
http://www.rlmueller.net
>> --
>>
>
> Sorry for the confusion. I copied your original "Set oRegistry", then
> recoded it and neglected to delete the copy. The code snippet should have
> just one "Set oRegistry" statement:
> ======
> On Error Resume Next
> Set oRegistry = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" _
> & strComputer & "\root\default:StdRegProv")
> If (Err.Number <> 0) Then
> On Error GoTo 0
> ' Error. Alert user, log, or whatever.
> Else
> On Error GoTo 0
> ' Continue.
> End If
> =======
> The idea is that I suspend normal error handling for just the one
> statement expected to raise an error.
>
> Also, I normally ping the remote computer to see it is even online and
> available. I have several functions for this linked here:
>
>
http://www.rlmueller.net/PingComputers.htm
>
> An example VBScript program that inventories computers is linked here:
>
>
http://www.rlmueller.net/Inventory.htm
>
> In this example I retrieve the names of all computers in the domain. I
> ping each one. If it responds, I attempt to connect with WMI. The program
> demonstrates how to handle all the things that can go wrong.
>
> The reason why I ping is because the timeout if "Set oRegistry" fails is
> quite long. I have never found any way to reduce the timeout. This timeout
> can be avoided if the computer is off line by pinging. The Ping function
> allows us to set a short timeout.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab -
http://www.rlmueller.net
> --
>
>