By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,213 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,213 IT Pros & Developers. It's quick & easy.

automatic reboot exception handling

P: n/a
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=impersonat e,(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?
Sep 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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?

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"cj" wrote:
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=impersonat e,(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?
Sep 24 '07 #2

P: n/a
cj
Sorry, hit send before finished

Exception from HRESULT:0x80041032.


Anand[MVP] wrote:
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?
Sep 24 '07 #3

P: n/a
cj
Anyone see any problems if I change the last code in form1.closing from

Dim WMIService, Computer As Object
WMIService =
GetObject("Winmgmts:{impersonationLevel=impersonat e,(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=impersonat e,(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

cj wrote:
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=impersonat e,(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?
Sep 24 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.