473,486 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

automatic reboot exception handling

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
3 1687
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2828
by: adi | last post by:
Dear all, This is more like a theoretical or conceptual question: which is better, using exception or return code for a .NET component? I had created a COM object (using VB6), which uses...
0
1885
by: Allan Bredahl | last post by:
Hi All I am trying to construct an application that is able to cancel a machine shutdown, reboot or logoff. And after performing some stuff to perform the original shutdown order :...
4
1875
by: Tom | last post by:
Hi I've created a windows service and it is set to run under local system account. But after its installed and after reboot when I check in the services its still sitting there and have not...
7
5961
by: Noor | last post by:
please tell the technique of centralize exception handling without try catch blocks in c#.
3
2734
by: Master of C++ | last post by:
Hi, I am an absolute newbie to Exception Handling, and I am trying to retrofit exception handling to a LOT of C++ code that I've written earlier. I am just looking for a bare-bones, low-tech...
44
4155
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
4412
by: Tom | last post by:
Hi I've created a windows service and it is set to run under local system account. But after its installed and after reboot when I check in the services its still sitting there and have not...
2
3067
by: Ty Moffett | last post by:
Below is a set of insructions that changes the registry keys pertaining to Automatic Updates on my Windows XP box. I can make changes using the control panel applet and see the changes reflected...
1
3086
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
0
7094
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5427
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3066
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.