[2005] Shutdown Help Needed!
I need to change the shudown on my computer so that when the shutdown button is clicked it stops the shutdown, runs my application and then shuts down the computer when my application has finished.
I've been thinking about having an application running all the time in the background and then cataching the shutdown command and stopping it, then running my application and then shutting down.
Does anyone have any code that can help with this please?
Thanks in advance.
------
KNXRB
Re: [2005] Shutdown Help Needed!
You can do this by two method. One is in the Form1_FormClosing and check for the
Code:
e.CloseReason=CloseReason.WindowsShutDown
and to the job there.
Another method you can use the system events to detect the shutdown
Code:
'Add two command buttons
Imports Microsoft.Win32
Imports System.EventArgs
Imports System
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AddHandler SystemEvents.SessionEnding, AddressOf ShutDownDetect
End Sub
Public Sub ShutDownDetect(ByVal sender As Object, ByVal e As EventArgs)
'Detect Shutdown and Do your job her
Me.Text = "Shutdown in Progress"
'Do your stuff here
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
RemoveHandler SystemEvents.TimeChanged, AddressOf ShutDownDetect
End Sub
Hope this helps.
Re: [2005] Shutdown Help Needed!
thanks. will try it later!
Re: [2005] Shutdown Help Needed!
Why does your app need to be run before the shutdown?
The Systemevents is your best bet since you state your app isnt running at the time.
Re: [2005] Shutdown Help Needed!
It will be a backup thing copying changed files from one path to another. This needs to run before it shuts down so that I don't lose any of the data I have changed since logging in.
Re: [2005] Shutdown Help Needed!
Well then try just coding in the save stuff to be called from the Closing event since it really doesnt matter what the reason is, just need to save it upon closing.
Re: [2005] Shutdown Help Needed!
I can't do that as the computer will just shutdown the backing up process and turn off. I can't start another thing as it shuts down.