Instead of doing this all the time...
strComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemSlot")
Do this...
strComputer = "."On Error Resume NextSet objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")If err.Number <> 0 Thenwscript.echo "error (" & err.Number & "): failed to connect to wmi instance"wscript.quitEnd IfSet colItems = objWMIService.ExecQuery("Select * from Win32_SystemSlot")
Make sure you get the object first, then get to work querying what's inside of it. It's a good habit to adopt.
No comments:
Post a Comment