TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > VB.NET

Notices

automatic reboot exception handling

VB.NET


Reply
 
Thread Tools Display Modes
Old 25-09-2007, 03:20 AM   #1
cj
Guest
 
Posts: n/a
automatic reboot exception handling

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?
  Reply With Quote
Old 25-09-2007, 03:20 AM   #2
Anand[MVP]
Guest
 
Posts: n/a
RE: automatic reboot exception handling

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



"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?
>

  Reply With Quote
Old 25-09-2007, 03:21 AM   #3
cj
Guest
 
Posts: n/a
Re: automatic reboot exception handling

yes, as the title of the unhandled exception box is the title of form1
of this program.


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?
>

  Reply With Quote
Old 25-09-2007, 03:21 AM   #4
cj
Guest
 
Posts: n/a
Re: automatic reboot exception handling

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?
>

  Reply With Quote
Old 25-09-2007, 03:22 AM   #5
cj
Guest
 
Posts: n/a
Re: automatic reboot exception handling

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?

  Reply With Quote
Old 09-01-2008, 10:03 PM   #6
Newbie
 
Join Date: Jan 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0 gazzi is an unknown quantity at this point
Re: automatic reboot exception handling

hi guy, i have this code to reboot my PC, is there a way i can reboot a remote host?

Dim WMIService, Computer AsObject
WMIService = GetObject("Winmgmts:{impersonationLevel=impersonat e,(Debug,Shutdown)}")
ForEach Computer In WMIService.InstancesOf("Win32_OperatingSystem")
Computer.Win32Shutdown(2 + 4, 0)
'reboot
Next
gazzi is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Good Book/Resource on Exception Handling. theinvisibleGhost C#(C Sharp) 0 21-09-2007 05:31 PM
Exception Handling - Good Practice CJM VB.NET 10 07-09-2007 03:32 AM
Windows doesn't reboot cleanly after automatic updates Robert S Windows XP 0 16-08-2007 06:07 PM
automatic updates automatic disable upon startup crapit Windows XP 2 16-08-2007 11:31 AM
Problem with c++ exception handling! drkm_4_frm Programming 3 19-09-2006 08:48 PM


< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 04:10 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional