Script than: on system shutdown, perform an action
#1
JamiePhonic
Posted 10 July 2012 - 11:45 PM
basically i need a script that, on system shutdown, it aborts the shutdown, selects the minecraft server Console window and types stop before waiting 10 seconds and then shutting down the system.
#2
Posted 10 July 2012 - 11:55 PM
#3
JamiePhonic
Posted 11 July 2012 - 12:04 AM
i just cant figure out the code
#4
Posted 11 July 2012 - 12:10 AM
#5
Posted 11 July 2012 - 12:19 AM
...when you do that, does the computer "begin shutting down" or just "immediately lose power"?i just press the power button.
Most power buttons on computers these days are more like a "soft power button", they inform the OS that you pressed power & give the OS the choice of what to do (which means the OS can shutdown cleanly -- or not shutdown at all).
If pressing the power button causes an "immediate loss of power", then it is "Game Over"...you have a computer with a "dumb" power button & there is nothing you can do, that includes being able to press the power button -- Also, if this is the case, STOP DOING THAT IMMEDIATELY...sudden power loss is REALLY BAD for a computer!
However, if not (if you have a computer with a "smart" power button), then a script can help you.
...not always, at least not with newer computers...& even semi-old computers (with a "smart" power button) do as mentioned above.AFAIK, when you press the power button, it's game over.
#6
JamiePhonic
Posted 11 July 2012 - 12:31 AM
when i press the power button, windows starts to shutdown the same way it would if i had gone to start==>shutdown.
#7
Posted 11 July 2012 - 12:38 AM
Related:
- <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?t=73680">viewtopic.php?t=73680</a><!-- l --> !!
- <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?t=26304">viewtopic.php?t=26304</a><!-- l -->
- <!-- l --><a class="postlink-local" href="http://www.autohotkey.com/community/viewtopic.php?p=338084#p338084">viewtopic.php?p=338084#p338084</a><!-- l -->
#8
Posted 11 July 2012 - 01:30 AM
OnMessage(0x11, "WM_QUERYENDSESSION")
Return ;Ends auto-execute section.
WM_QUERYENDSESSION()
{
Do what you gotta do
}
Return
#9
JamiePhonic
Posted 11 July 2012 - 01:21 PM
OnMessage(0x11, "WM_QUERYENDSESSION")
Return ;Ends auto-execute section.
WM_QUERYENDSESSION()
{
If WinExist("ahk_class ConsoleWindowClass")
WinActivate
sleep, 250
sendinput, stop{enter}
sleep 5000
}
Returnthe problem with this code is that because the minecraft server is one of only 5 program running, windows kills it before the script can do its job.what ive decided to do is go into the power options and set:
When i press the power button on my computer: Do nothing.so that windows no longer shuts down when i press the power button.
im wondering if there's a way for autohotkey to detect that ive pressed the power button and then run the script before initiating the shutdown using something like "shutdown -s -t0" (CMD shutdown code) or autohotkeys own version of it?
#10
Posted 11 July 2012 - 01:58 PM
#11
JamiePhonic
Posted 11 July 2012 - 02:17 PM
there's not enough processes to make a difference.Maybe if you changed some Windows priorities around it would make a difference?
the server runs: a minecraft server, PS3 media server and uTorrent. that's it
#12
JamiePhonic
Posted 11 July 2012 - 03:38 PM
DllCall("kernel32.dll\SetProcessShutdownParameters", UInt, 0x4FF, UInt, 0) ;make windows kill this process first
OnMessage(0x11, "WM_QUERYENDSESSION")
return
WM_QUERYENDSESSION(wParam, lParam)
{
ENDSESSION_LOGOFF = 0x80000000
If WinExist("ahk_class ConsoleWindowClass") ;if a cmd window is open,
{
WinActivate ;switch to it
sleep, 500 ;wait half a second
sendinput, stop{enter} ;type stop, press enter
sleep 5000 ;wait 5 seconds
return true ; Tell the OS to allow the shutdown/logoff to continue.
exitapp ;quit the program
}
else ; if the cmd window is already closed,
return true ; Tell the OS to allow the shutdown/logoff to continue.
exitapp ;quit the program
}
#13
Posted 11 July 2012 - 03:40 PM
what ive decided to do is go into the power options and set:
When i press the power button on my computer: Do nothing.so that windows no longer shuts down when i press the power button.
im wondering if there's a way for autohotkey to detect that ive pressed the power button and then run the script before initiating the shutdown using something like "shutdown -s -t0" (CMD shutdown code) or autohotkeys own version of it?
How about this idea
keep the power management set the way you have it (When you press the power button, nothing happens), but now create a Hotkey for shutting the PC down instead
[color=#BF0000]^!s::[/color]
{
If WinExist("ahk_class ConsoleWindowClass")
WinActivate
sleep, 250
sendinput, stop{enter}
sleep 5000
}
[color=#BF0000]Shutdown 8[/color]
#14
JamiePhonic
Posted 12 July 2012 - 05:06 PM
How about this idea
keep the power management set the way you have it (When you press the power button, nothing happens), but now create a Hotkey for shutting the PC down instead[color=#BF0000]^!s::[/color] { If WinExist("ahk_class ConsoleWindowClass") WinActivate sleep, 250 sendinput, stop{enter} sleep 5000 } [color=#BF0000]Shutdown 8[/color]
that's no use. its a headless server. (no keyboard, mouse or monitor. its all configured over remote desktop)




