Thread: GetObject Trap
View Single Post
  #2 (permalink)  
Old November 23rd, 2004, 08:37 AM
mmcdonal mmcdonal is offline
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   As a test, why not try this:

'====================================
Dim stError

On Error Resume Next
Err.Clear

 Set oReg=GetObject("winmgmts:{impersonationLevel=imper sonate}!\\" & _
            ComputerName & "\root\default:StdRegProv")

stError = Err
WScript.Echo stError
'=========================================

On my Windows XP machine, I get this error returned:

-2147217375

If the rest of your code has error handling, or is running fine, then you can trap this value and do something like

'=============================
If Err = -2147217375 Then ' or "If Err <> 0 Then"
   Set WshShell = WScript.CreateObject("WScript.Shell")
   WshShell.LogEvent 0, "MyScript.vbs: Error " & stError 'or some message
   WScript.Quit
End If
'=============================

if this value is returned. This posts a message to the Event Logs that tells you the script attempted to run, but this error was returned.

You could then put a routine at the beginning of the script that checks for this event log entry and either does something else or quits before it even gets to this point again.

You could also check the version of the OS in another routine at the beginning of the script and tailor the script for each OS version it detects, but this may cause the same sort of failure as above.









mmcdonal
Reply With Quote