Roman Posted October 4, 2012 Share Posted October 4, 2012 (edited) Hi Is there a possibility that I can intercept a Windwos reboot and to convert this "reboot" command to a "shutdown" command? Regards, Roman. Edited October 4, 2012 by roman Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 (edited) Hi, Yes it is. expandcollapse popup#include <WindowsConstants.au3> Global $blQuit = False #region GUI $GUI = GUICreate("QUERYENDSESSION EVENT") GUIRegisterMsg($WM_QUERYENDSESSION, "WM_QUERYENDSESSION") GUIRegisterMsg($WM_ENDSESSION, "WM_ENDSESSION") GUIRegisterMsg($WM_POWERBROADCAST, "WM_POWERBROADCAST") GUISetState(@SW_HIDE, $GUI) #endregion GUI _SetProcessShutdownParameters(0xFFF) ;set highest notification level _ThreadExecutionState_Set() While 1 If $blQuit Then ExitLoop Sleep(1000) WEnd Shutdown(1) ;convert to normal shutdown Exit 0 Func WM_ENDSESSION($hWnd, $iMsg, $wlParam, $ilParam) Return False EndFunc ;==>WM_ENDSESSION Func WM_QUERYENDSESSION($hWnd, $iMsg, $wlParam, $ilParam) $blQuit = True Return False ;block endsession EndFunc ;==>WM_QUERYENDSESSION Func WM_POWERBROADCAST($hWnd, $iMsg, $wlParam, $ilParam) Return 1 EndFunc ;==>WM_POWERBROADCAST Func _ThreadExecutionState_Set() ;The ES_AWAYMODE_REQUIRED value should be used only when absolutely necessary by media applications that require the system ;to perform background tasks such as recording television content or streaming media to other devices while the system appears to be sleeping Local $aResult = DllCall("kernel32.dll", "int", "SetThreadExecutionState", "int", BitOR($ES_CONTINUOUS, $ES_SYSTEM_REQUIRED, $ES_AWAYMODE_REQUIRED)) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ;==>_ThreadExecutionState_Set Func _SetProcessShutdownParameters($dwLevel, $dwFlags = 0) ; http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx ; Prog@ndy Local $aResult = DllCall("Kernel32.dll", "int", "SetProcessShutdownParameters", "dword", $dwLevel, "dword", $dwFlags) If @error Then Return SetError(1, 0, 0) Return $aResult[0] EndFunc ;==>_SetProcessShutdownParameters Br, FireFox. Edited October 4, 2012 by FireFox Link to comment Share on other sites More sharing options...
Roman Posted October 4, 2012 Author Share Posted October 4, 2012 (edited) HiThanks! But I get some AutoIt errors (some variables "...possibly used before declaration")?I would be very interested in your script, although I don't understand why do you use "GUI commands"? Maybe I didn't pose my question very exactly:I want to intercept every and any Windows reboot, never mind if it is initiated by user, an application or by the system itself, e.g. after an application installation or after a reboot initiated by microsoft update(s).Kind regards,Roman. Edited October 4, 2012 by roman Link to comment Share on other sites More sharing options...
guinness Posted October 4, 2012 Share Posted October 4, 2012 Because Windows broadcasts the message WM_QUERYENDSESSION to all windows, hence why you need a GUI. Also learn how to debug correctly please, if you had searched the help file for those variables you would have found that WindowsConstants.au3 needs to be included. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Roman Posted October 4, 2012 Author Share Posted October 4, 2012 It doesn't run as well with WindowsConstants.au3 included, but never mind; I may be an AutoIt dummy - that's true - and simply hoped to get some fast help in this forum.I apologize for my ignorance and will do now some research and debugging for my own.Regards,Roman. Link to comment Share on other sites More sharing options...
guinness Posted October 4, 2012 Share Posted October 4, 2012 You're not a dummy, add these to the top of the script as well. Also you did get some fast help. Global Const $ES_AWAYMODE_REQUIRED = 0x00000040 Global Const $ES_CONTINUOUS = 0x80000000 Global Const $ES_SYSTEM_REQUIRED = 0x00000001 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
rudi Posted October 4, 2012 Share Posted October 4, 2012 Hi Guinnes, is this broadcast also fact, if the shutdown is a "forced" one? Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 (edited) My bad... just stripped some parts of a project and removed the Constants. @rudi If you mean shutdown by pressing the power button for few seconds then it's not possible, otherwise it is. Edited October 4, 2012 by FireFox Link to comment Share on other sites More sharing options...
guinness Posted October 4, 2012 Share Posted October 4, 2012 No idea without doing some research. I would presume No, but that's a presumption. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
UEZ Posted October 4, 2012 Share Posted October 4, 2012 Sorry for hijacking this thread but I wanted to know whether it is possible to intercept a process kill. E.g. when my script without GUI is running via Task Scheduler and somebody presses the stop button in TS for that particular process (my script) how can I intercept it and write it to a log file? The interessting part is the interception! Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
rudi Posted October 4, 2012 Share Posted October 4, 2012 (edited) Hi Firefox.@rudiIf you mean shutdown by pressing the power button for few seconds then it's not possible, otherwise it is.Well, I was wondering about that nice "Shutdown -r -t 0 -f", but ACPI initiated "shutdown" might be a forced one as well. A "Brute" poweroff using the powerbutton itself is propably "un-interceptable" -- on the other hand: That signal is going "through" the motherboard, so there might be a chance, to reset the "hold-time-counter" there.Regards, Rudi. Edited October 4, 2012 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 (edited) Well, I was wondering about that nice "Shutdown -r -t 0 -f", but ACPI initiated "shutdown" might be a forced one as well. Try it yourself , but I'm almsot sure that It will be intercepted otherwise setting the notification level would be useless. A "Brute" poweroff using the powerbutton itself is propably "un-interceptable" -- on the other hand: That signal is going "through" the motherboard, so there might be a chance, to reset the "hold-time-counter" there. That's what I meant by "it's not possible", so good catch. Edit : @UEZ This is a good question, If you think about it I would say It's not possible to intercept it with the process being killed (have you ever seen a process unkillable when you have all the permissions to kill it?) but with another one it's another question. (then it's useless [ProcessExists etc]) Br, FireFox. Edited October 4, 2012 by FireFox Link to comment Share on other sites More sharing options...
UEZ Posted October 4, 2012 Share Posted October 4, 2012 (edited) Well, I don't want to run an additional script to monitor the main script. Is there any triggering from the TS to the any winapi or the scripts that says "I'm going to stop you now". In this case you can do the last actions before it will shutdown the process. Br, UEZ Edited October 4, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 (edited) @UEZ,After some searches, I have not found what you were looking for; I would say almost :If you click on the button "End task" after selecting the window in the TaskManager then it will send a $WM_CLOSE message to the GUI; if you block this message by returning False, then the TaskManager will think that the application is not responding so it will suggest you to kill the application, which is not very good.So I have found an alternative, when the GUI receive the $WM_CLOSE message, the script execute another instance and close the first one, so there is always one instance running.Instead of that you could make your last actions and exit normally.#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #region GUI GUICreate("toto") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUIRegisterMsg($WM_CLOSE, "WM_CLOSE") GUISetState() #endregion GUI While 1 Sleep(100) WEnd Func WM_CLOSE($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_CLOSE ShellExecute(@ScriptFullPath) EndSwitch _Exit() EndFunc ;==>WM_CLOSE Func _Exit() Exit 0 EndFunc ;==>_ExitBr, FireFox. Edited October 4, 2012 by FireFox Mechaflash and UEZ 2 Link to comment Share on other sites More sharing options...
UEZ Posted October 4, 2012 Share Posted October 4, 2012 Thank you very much FireFox! Creating a dummy hidden window and GUIRegisterMsg($WM_CLOSE, "WM_CLOSE") did the trick! Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Mechaflash Posted October 4, 2012 Share Posted October 4, 2012 Good find Firefox Spoiler “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.” Link to comment Share on other sites More sharing options...
FireFox Posted October 4, 2012 Share Posted October 4, 2012 @UEZ You're welcome, I'm glad this is what you were looking for @Mechaflash Thanks. Br, FireFox. Link to comment Share on other sites More sharing options...
JohnQSmith Posted October 4, 2012 Share Posted October 4, 2012 I would presume No, but that's a presumption.Is that a redundant redundancy? Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes". Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now