how to run the execuatable before windows shutting down

L

leocwh

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
 
G

GhostInAK

Hello (e-mail address removed),

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
 
P

Phill W.

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.
 
M

Mike Lowery

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top