Board index » Visual Studio » how to run the execuatable before windows shutting down

how to run the execuatable before windows shutting down

Visual Studio89
Dear all,



I would like to know how to run the execuatable before windows shutting

down.

Here is my simple code:

Private Sub Command1_Click()

Shell "C:\abc.bat", vbNormalFocus

End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = vbAppWindows Then

Shell "C:\abc.bat", vbNormalFocus

MsgBox "Finished!!"

End If

End Sub



Private Sub Form_Unload(Cancel As Integer)

Call Command1_Click

End Sub



When I click Command1, it works

When I shut down the Windows, the message box comes out but cannot

execute "abc.bat".

because after executed "abc.bat", a result file will be created.



Do any expert can help me?



Thanks


-
 

Re:how to run the execuatable before windows shutting down

Hello leocwh@gmail.com,



You'll have to cancel the shutdown, launch your app, and then initiate a

second shutdown.



This is NOT a good idea. shutting down a system is NOT the time to be launching

apps. Cancelling a user-requested shutdown is punishable by castration in

some places. Rethink your design.



-Boo



Quote
Dear all,



I would like to know how to run the execuatable before windows

shutting

down.

Here is my simple code:

Private Sub Command1_Click()

Shell "C:\abc.bat", vbNormalFocus

End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = vbAppWindows Then

Shell "C:\abc.bat", vbNormalFocus

MsgBox "Finished!!"

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

Call Command1_Click

End Sub

When I click Command1, it works

When I shut down the Windows, the message box comes out but cannot

execute "abc.bat".

because after executed "abc.bat", a result file will be created.

Do any expert can help me?



Thanks







-

Re:how to run the execuatable before windows shutting down

leocwh@gmail.com wrote:



Quote
I would like to know how to run the execuatable before windows shutting

down.



Why?

What do you want this program to do?



When Windows shuts down, it can be quite harsh in its treatment of

running processes - have you ever seen the "End Now" dialog? You cannot

override that kind of behaviour.



Whatever it is you need to do, how about doing it the next time Windows

/starts up/? Just add a shortcut into the StartUp group. It's easier

to see what's going on and more reliable.



HTH,

Phill W.





Quote
Here is my simple code:

Private Sub Command1_Click()

Shell "C:\abc.bat", vbNormalFocus

End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = vbAppWindows Then

Shell "C:\abc.bat", vbNormalFocus

MsgBox "Finished!!"

End If

End Sub



Private Sub Form_Unload(Cancel As Integer)

Call Command1_Click

End Sub



When I click Command1, it works

When I shut down the Windows, the message box comes out but cannot

execute "abc.bat".

because after executed "abc.bat", a result file will be created.



Do any expert can help me?



Thanks



-

Re:how to run the execuatable before windows shutting down

Not sure if this will work for you, but you can assign a Shutdown script using

Group Policy.



<leocwh@gmail.com>wrote in message

Quote
Dear all,



I would like to know how to run the execuatable before windows shutting

down.

Here is my simple code:

Private Sub Command1_Click()

Shell "C:\abc.bat", vbNormalFocus

End Sub



Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

If UnloadMode = vbAppWindows Then

Shell "C:\abc.bat", vbNormalFocus

MsgBox "Finished!!"

End If

End Sub



Private Sub Form_Unload(Cancel As Integer)

Call Command1_Click

End Sub



When I click Command1, it works

When I shut down the Windows, the message box comes out but cannot

execute "abc.bat".

because after executed "abc.bat", a result file will be created.



Do any expert can help me?



Thanks







-