automatic reboot exception handling

C

cj

My program shuts itself down and reboots the pc it's running on at
2:00am twice a week and has been doing so without fail for over a year.
But twice in the past month it's been found running in the AM with an
unhandled exception on the screen. As best I can tell this exception
occurs while it's trying to reboot the pc. This has me thinking it
might be nice to have it do a reboot whenever it has an unhandled
exception but then again I'm sure it's the rebooting that's causing the
exception. If I put the try catch code around the reboot code

Dim WMIService, Computer As Object
WMIService =
GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
For Each Computer In WMIService.InstancesOf("Win32_OperatingSystem")
Computer.Win32Shutdown(2 + 4, 0) 'reboot
Next

then if it throws an exception it will not reboot and the program will
be left running but nonfunctional as everything was stopped just before
the reboot code--which is actually worse than getting the unhandled
exception.

Can I put this reboot code in the unhandled exception event for my
application as well and if in the form closing event. If it throws an
exception in the form closing event or anywhere else I'm not catching
them it would then try to reboot or reboot again?

What if the code in the unhandled exception event throws and exception?
 
G

Guest

Are you sure it is this program that is throwing an exception? It maybe due
to someother program that has a faulty shutdown code that is throwing an
exception and stopping the reboot?

What exception are you getting?
 
C

cj

Anyone see any problems if I change the last code in form1.closing from

Dim WMIService, Computer As Object
WMIService =
GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
For Each Computer In WMIService.InstancesOf("Win32_OperatingSystem")
Computer.Win32Shutdown(2 + 4, 0) 'reboot
Next

to

Dim rebootErr As Boolean = False
Do
Try
Dim WMIService, Computer As Object
WMIService =
GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
For Each Computer In WMIService.InstancesOf("Win32_OperatingSystem")
Computer.Win32Shutdown(2 + 4, 0) 'reboot
Next
rebootErr=False
Catch ex As Exception
'log error
rebootErr=True
End Try
Loop While rebootErr = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top