Jump to content

[Closed] Detect type of windows shut down


Recommended Posts

When ever my pc shuts own, its always hangs by some application and just looks horrible.

It normally comes 2 the case where i need to do a force shutdown.

Before i tryed the idea of autoits Exit-Method and then making it do a forced restart.

Is there any way for the exit method to tell if the pc is shutting down "in which case do a forced shutdown" or is restarted "in which case do a forced restart"?

Edited by IanN1990
Link to comment
Share on other sites

Maybe you can try to detect the window that tells you some time that you need to force end some processes.

Why don't you try to fix the Windows problem? check if it's internal and use the command-line (DOS) typing ( sfc /scannow ) - you might need the Windows Installation Disk if your OS is under Win Vista.

Good luck.

[font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font]

Link to comment
Share on other sites

You need to set up a message handler using GUIRegisterMsg() for WM_QUERYENDSESSION

and then take the appropriate action when windows send the WM_QUERYENDSESSION message prior to shutting down.

see MSDN for details http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890(v=vs.85).aspx

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Is there any way for the exit method to tell if the pc is shutting down "in which case do a forced shutdown" or is restarted "in which case do a forced restart"?

This is a frequently asked question on the net. And the answer is always no. It is not possible to destinguish between shutdown and restart. It is crazy, but that is the way it is. (Atleast not in any straightforward way... Maybe hook shutdown-API... or other things...)

/Manko

Edited by Manko
Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

This is a frequently asked question on the net. And the answer is always no. It is not possible to destinguish between shutdown and restart. It is crazy, but that is the way it is. (Atleast not in any straightforward way... Maybe hook shutdown-API... or other things...)

/Manko

That's generally because the OS takes care of the difference. It does not matter to the program in the slightest what the OS is doing. All it (the program) was told to do was close. Period. And that's really all it needs to do. The why is moot.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

It seems to be an issue with Windows not telling applications that it's rebooting rather than just shutting down, so a UDF probably wouldn't be easy to accomplish. Look on Stackoverflow.com for how many times this gets asked and the answer is always that it would be very hard to detect if possible at all.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 2 weeks later...

Yea searching the forums it seams alot of people ask this similar question with no answer or the answer requires a high level of coding + windows understanding. Maybe some day someone could make a UDF on it, as it would be quite useful :)

If you really found some examples that can do this, please point the way, because I have not found anything like that.

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

just incase someone finds this one day and does know the answer but is a ltitle confused the end result would be something like this.

If Computer is shuttingdown then

Shutdown(17) "16 force if hung and 1 is shutdown)

elseif computer is rebooting then

shutdown(18) "16 force if hung and 2 is reboot)

else

do nothing and exit normally

endif

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...