Results 1 to 22 of 22

Thread: How to call an exe on shut down

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2002
    Location
    Mumbai
    Posts
    10

    How to call an exe on shut down

    Hello everybody,
    Does any one know how to call an exe on windows shut down.
    Actually, while leaving the office every day we need to log off from one of our web site.
    Some people forget logging off, hence needs some utility which will get fired on windows shut down.

    Thanks
    Pal

  2. #2
    Junior Member
    Join Date
    May 2002
    Location
    Puerto Rico
    Posts
    29
    Would a scheduled task would work?

  3. #3
    Frenzied Member ice_531's Avatar
    Join Date
    Aug 2002
    Location
    Sitting w/ Bob Status: -Next -To- Null- Friend: Philip
    Posts
    1,152
    I dont quite understand your question.....whether u want to start program with windows startup? or start a program as windows shutsdown (not sure how this is possible.since windows wud shut the program off b4 completely shutting down)

    so gerardofpr mite be correct...scheduled task ?
    :::`DISCLAIMER`:::
    Do NOT take anything i have posted to be truthful in any way, shape or form.
    Thank You!

    --------------------------------
    "Never heard about "hiking" poles. I usualy just grab a stick from the nature, and use that as a pole." - NoteMe
    "Finaly I can look as gay as I want..." - NoteMe
    Languages: VB6, BASIC, Java, C#. C++

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    It seems that when the PC is closing it sends the WM_QUERYENDSESSION message to all the programs to close. Try trapping it


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770
    No, I dont think this can be done. Because once windows sends the SHUTDOWN notification it wont attemt to handle execution of applications anylonger and will shut down all current running programs during the OS shutdown process..


    A website shouldn't require you to log off when you are done. Unless they are just trying to keep you safe by making sure you close an IE windows so it flushes the cookies the sites used. Otherwise if your shutting down your system then it really wouldnt matter, regardless...

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    Originally posted by nkad
    No, I dont think this can be done. Because once windows sends the SHUTDOWN notification it wont attemt to handle execution of applications anylonger and will shut down all current running programs during the OS shutdown process..
    That's only during an emergancy or forced shutdown. For a regular shut down, Windows will send the proper messages to each application. (That's actually part of the reason why we have the shut down in the first place)

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Megatron
    That's only during an emergancy or forced shutdown. For a regular shut down, Windows will send the proper messages to each application. (That's actually part of the reason why we have the shut down in the first place)
    So my way makes sence?


    Has someone helped you? Then you can Rate their helpful post.

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    In WIndows XP, you can trap that message like said before, once you get that message execute a "shutdown -a" to abort the shutdown, run your programs and then shutdown the system

  9. #9
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Originally posted by Megatron
    That's only during an emergancy or forced shutdown. For a regular shut down, Windows will send the proper messages to each application. (That's actually part of the reason why we have the shut down in the first place)
    HA! Here's to a guy that helped me alot in my first forays into VB from Java!

    Wondered if you disappeared or changed your username, but it appears you just don't visit the .Net forums.

  10. #10
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    Originally posted by kasracer
    In WIndows XP, you can trap that message like said before, once you get that message execute a "shutdown -a" to abort the shutdown, run your programs and then shutdown the system
    Nice work....but three minor problems....


    #1 - You'll have to have the host application constantly running (whther in the system tray, hidden, process or service....)

    #2 - What's gonna happen when it tries to initialise the finishing shutdown sequence.....Won't it loop....
    What I mean is this....
    The OS tries to shut down... the program traps that and prevents it, it runs a sequence of events and when finished it shuts down the PC....
    Won't it treat that new shutdown as a normal shutdown and repeat the processes?

    #3 - The abort shutdown will only abort shutdown of the OS if it was that application that started the shutdown in the first place, else it would be ignored....

    Plus, on a side note... if you tried that on WinXP, and presumably all other WinOSs, a message will popup saying that this program is not responding and after a certain time it will forcefully terminate the program....
    So just make sure that whatever you are doing is done fast enough...

    Sorry to be the kill joy, but I don't like to see people get happy over a pseudo~solution...
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  11. #11
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    For 2 I guess you can have a flag that you change accordingly each time you process the shutdown message.

    Sort of like this :

    If boolean=true then
    do all sorts of stuff
    set boolean=false
    endif

    so next time you process the shutdown message is sent it won't cancel it


    Has someone helped you? Then you can Rate their helpful post.

  12. #12
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    Well that's 1 down.....2 left to go....
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  13. #13
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Why is 1 a problem? Is there another way to do it?


    Has someone helped you? Then you can Rate their helpful post.

  14. #14
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    I read yah @^

    I guess that's not really a problem... so that makes 2 down....but we still have to solve the last one, and that one will prove to be the killer (no pun intended)

    I was searching through the API Viewer and I saw this function:
    VB Code:
    1. Declare Function AbortSystemShutdown Lib "advapi32.dll" Alias "AbortSystemShutdownA" ( _
    2.      ByVal lpMachineName As String) As Long
    I can't seem to get it to work.... anyone familiar with this function, and can help?


    (P.S. When this thread gets resolved, I'll be the first to bookmark it....)
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  15. #15
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Weird... I can't find any examples with that API that work...


    Has someone helped you? Then you can Rate their helpful post.

  16. #16
    Addicted Member
    Join Date
    Aug 2003
    Location
    USA
    Posts
    145

  17. #17
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    AbortSystemShutdown

    The AbortSystemShutdown function stops a system shutdown started by using the InitiateSystemShutdown function.

    Parameters:
    lpMachineName
    [in] Pointer to the null-terminated string that specifies the network name of the computer where the shutdown is to be stopped. If lpMachineName is NULL or an empty string, the function stops the shutdown on the local computer.
    Return Values
    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    Remarks:
    The InitiateSystemShutdown and InitiateSystemShutdownEx functions display a dialog box that notifies the user that the system is shutting down. During the shutdown time-out period, the AbortSystemShutdown function can prevent the system from shutting down.
    Abstract from the above link....

    After reading that then I know for sure why I never got the function to work and why it would never succeed in this case....

    So I guess this is hopeless and will remain unresolved....
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  18. #18
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    After reading that then I know for sure why I never got the function to work and why it would never succeed in this case....
    Why?


    Has someone helped you? Then you can Rate their helpful post.

  19. #19
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    The AbortSystemShutdown function stops a system shutdown started by using the InitiateSystemShutdown function

    The AbortSystemShutdown will only work if the system was shut down by using the InitiateSystemShutdown function...
    Seeing the InitiateSystemShutdown is restricted to the application that called it, that makes it something like what kasracer said with the "shutdown - a" to abort...

    Both cases will not work because it is restricted to the application that called it... Which means that if (example) Norton called the InitiateSystemShutdown after installing an update, then your application cannot AbortSystemShutdown to cancel out that effect.
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  20. #20
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Protocol

    #1 - You'll have to have the host application constantly running (whther in the system tray, hidden, process or service....)

    #2 - What's gonna happen when it tries to initialise the finishing shutdown sequence.....Won't it loop....
    What I mean is this....
    The OS tries to shut down... the program traps that and prevents it, it runs a sequence of events and when finished it shuts down the PC....
    Won't it treat that new shutdown as a normal shutdown and repeat the processes?

    #3 - The abort shutdown will only abort shutdown of the OS if it was that application that started the shutdown in the first place, else it would be ignored....
    1. He is going to have to do that anyway. There is no magical API WhenShutDownOccursRunProgram(omg.exe)

    2. It's called flags like already mentioned

    3. I've used it before when programs have started a restart or shutdown after an update. Actually I've done it alot, and it always worked

    Originally posted by Protocol

    Plus, on a side note... if you tried that on WinXP, and presumably all other WinOSs, a message will popup saying that this program is not responding and after a certain time it will forcefully terminate the program....
    So just make sure that whatever you are doing is done fast enough...
    Only if the system is shutting down. If you send shutdown -a to it, it won't do that. If a shutdown is initiated and isn't aborted, it stops the execution of code, you will have an almost impossible timeframe to use for the program.

    I think the thread starter should just make a timeout for the server so when the connection is lost, after X minutes it disconnects/logs the user out. A client side program isn't really the solution for this sort of problem.

  21. #21
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Hm, didn't notice that... Damn...


    Has someone helped you? Then you can Rate their helpful post.

  22. #22
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    kasracer:
    I think the thread starter should just make a timeout for the server so when the connection is lost, after X minutes it disconnects/logs the user out. A client side program isn't really the solution for this sort of problem.
    True that...I was thinking of that also...



    P.S. I still can't get the "shutdown - a" to work...maybe it's just my PC.....

    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width