Home All Groups Group Topic Archive Search About

how to run the execuatable before windows shutting down

Author
27 Sep 2006 4:59 AM
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

Author
27 Sep 2006 5:41 AM
GhostInAK
Hello leo***@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

Show quoteHide 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
>
Author
27 Sep 2006 8:30 AM
Phill W.
leo***@gmail.com wrote:

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


Show quoteHide 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
>
Author
28 Sep 2006 4:37 PM
Mike Lowery
Not sure if this will work for you, but you can assign a Shutdown script using
Group Policy.

<leo***@gmail.com> wrote in message
Show quoteHide quote
news:1159333199.742678.132480@m7g2000cwm.googlegroups.com...
> 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
>