Re: Finetuning: Remote Shutdown with WMI, some errors occur.
- From: Jason Gurtz <jasonNOgurtz@xxxxxxxxxxxxxxx>
- Date: Tue, 28 Mar 2006 11:24:36 -0500
Joris van der Struijk wrote:
Most of the time it workes, but sometimes it stops in error saying something
like: "External server not available" or "shutdown.vbs(49, 9) (null):
0x80041021)" or "(57, 13) SWbemObjectEx: The RPC Server is Unavailable".
These errors are indicative of network problems or timeouts or something
like that. It might also be a transient problem due to opening the ADO
connection and then holding it open for a potentially long time after
doing objCommand.Execute Maybe try closing the objConnection before
doing the shutdown looping.
Also sometimes it can't ping a computer but i know it turned on, and
available. When i try pinging myself it works.
Yea, sometimes if a machine is "sleeping" or network is unused the first
few pings do not come back. Modify your pinging section to have a
"priming ping". Just add add another objShell.Run line right above the
existing line but don't redirect output to the temp file. It might be
easier and cleaner to test the return value instead of parsing ping's
output. See the second example 1 here:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/0a8270d7-7d8f-4368-b2a7-065acb52fc54.asp>
if the return value is 0 then it was a success, 1 happens if host is
unreachable. Note the race condition if the host was up for the first
ping and then goes down. You will still see a success return value.
Hopefully that would be a rare occurrence.
What i would like is for the script to have some error handling so it
doesn't stop executing and take out those nasty bugs. Im no great programmer,
so could realy use some help.
try using "On Error"
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/0a8270d7-7d8f-4368-b2a7-065acb52fc54.asp>
A better example of use may be to define a little section at the bottom
of each function like so:
Function myFunction()
On Error GoTo HandleErr 'see, goto isn't always bad ;)
'Do Stuff
.
.
.
myFunction = True
Exit Function 'So normally we won't go past here
HandleErr:
MsgBox Err.Number & vbCrLf & Err.Description
'Put other error handling here (call functions, subs, whatever)
myFunction = False
End Function
So then you could call your function like this:
If myFunction() = True Then
'Do stuff when myFunction() succeeds
Else
'Do stuff when myFunction() fails
End If
Of course the cheap way out is to put "On Error Resume Next" at the very
top. Be careful, that's really just ignoring all errors, not handling them.
If you want to go hog wild, try testing the value of the WbemErrorEnum
constant after your WMI calls.
~Jason
--
.
- References:
- Finetuning: Remote Shutdown with WMI, some errors occur.
- From: Joris van der Struijk
- Finetuning: Remote Shutdown with WMI, some errors occur.
- Prev by Date: Re: WMI remote authentication
- Next by Date: Re: Need script to add Client for Microsoft Networks & remove NetWare client
- Previous by thread: Re: Finetuning: Remote Shutdown with WMI, some errors occur.
- Next by thread: Re: Finetuning: Remote Shutdown with WMI, some errors occur.
- Index(es):
Relevant Pages
|