hot202 Posted February 11, 2010 Share Posted February 11, 2010 i have this script and i have tryed many on here but i cant find any that keep the program running when it stops the shut down is there anyway u can keep the autoit program running or a msgbox pop up saying if u shut down it will exit the autoit script and if u cancel it wont shut down and the autoit script wont close? Opt("TrayIconHide", 1) $WM_QUERYENDSESSION = 0x0011 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) Global $b_ShutdownInitiated = False While 1 If $b_ShutdownInitiated = True then ;Do stuff here ;do some more stuff here ;DoTheShutDownStuff();maybe do some more stuff here ;) ;Shutdown();Maybe you want to shutdown the computer when done Exit;otherwise, you just exit this script EndIf sleep(10) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ;~ run(@ScriptDir & "\killpgm.exe") $b_ShutdownInitiated = True Return False EndFunc Link to comment Share on other sites More sharing options...
Juvigy Posted February 11, 2010 Share Posted February 11, 2010 Something like this? Opt("TrayIconHide", 1) $WM_QUERYENDSESSION = 0x0011 GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) Global $b_ShutdownInitiated = False While 1 If $b_ShutdownInitiated = True then $test=MsgBox(1,"Do you want to shutdown","OK to shutdown and Cancel to abort") If $test = 2 then sleep(10000) ;user chose not to shutdown Else Exit ;user chose to shutdown and the script exits EndIf WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) ;~ run(@ScriptDir & "\killpgm.exe") $b_ShutdownInitiated = True Return False EndFunc Link to comment Share on other sites More sharing options...
MvGulik Posted February 11, 2010 Share Posted February 11, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Steveiwonder Posted February 11, 2010 Share Posted February 11, 2010 (edited) I know if you go start> Run and type "shutdown -a" it will abort a system shutdown. So Run(@ComSpec & "/c shutdown -a") Edited February 11, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
NerdFencer Posted February 11, 2010 Share Posted February 11, 2010 You can skip cmd and hide the window like this... ShellExecute("shutdown","-a",Default,Default,@SW_HIDE) _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
MvGulik Posted February 12, 2010 Share Posted February 12, 2010 (edited) whatever Edited February 7, 2011 by MvGulik "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Gogeta70 Posted February 12, 2010 Share Posted February 12, 2010 Well, if you do manage to detect a shutdown, then i suggest the following. When you detect the shutdown, automatically cancel the shutdown with the code mentioned above (Shutdown -a), and then if the user chooses to continue the shutdown, reinitiate the shutdown with a (Shutdown -s -t 0 - i think). Good luck Link to comment Share on other sites More sharing options...
ferrierd Posted April 28, 2011 Share Posted April 28, 2011 Hi, First sorry for my bad English I try this script on XP it works perfectly On Vista/Seven it didn't works. I read that we must use DllCall("User32.dll", "int", "ShutdownBlockReasonDestroy" / DllCall("User32.dll", "int", "ShutdownBlockReasonCreate" Does someone got experience for "Aborting Shutdown" in Vista/Seven OS. Thanks, David Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2011 Share Posted April 28, 2011 expandcollapse popup#Include <ButtonConstants.au3> #Include <GUIConstantsEx.au3> #Include <WinAPIEx.au3> Opt('MustDeclareVars', 1) If _WinAPI_GetVersion() < '6.0' Then MsgBox(16, 'Error', 'Require Windows Vista or later.') Exit EndIf Global $hForm, $Msg, $Button, $Check $hForm = GUICreate('MyGUI', 200, 200) $Button = GUICtrlCreateButton('', 73, 62, 54, 54, $BS_ICON) GUICtrlSetImage(-1, @SystemDir & '\shell32.dll', 45) GUICtrlSetTip(-1, 'Log off ' & @UserName) $Check = GUICtrlCreateCheckBox('Block Windows shutdown', 10, 173, 144, 21) GUIRegisterMsg(0x0011, 'WM_QUERYENDSESSION') GUISetState() ; Set the highest shutdown priority for the current process to prevent closure the other processes. _WinAPI_SetProcessShutdownParameters(0x03FF) While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $Button Shutdown(0) Case $Check If GUICtrlRead($Check) = $GUI_CHECKED Then _WinAPI_ShutdownBlockReasonCreate($hForm, 'This application is blocking system shutdown because the saving critical data is in progress.') Else _WinAPI_ShutdownBlockReasonDestroy($hForm) EndIf EndSwitch WEnd Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $hForm If _WinAPI_ShutdownBlockReasonQuery($hForm) Then Return 0 EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_QUERYENDSESSION My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Yashied Posted April 28, 2011 Share Posted April 28, 2011 Another example. expandcollapse popup#Include <GUIConstantsEx.au3> #Include <WinAPIEx.au3> Global $Shutdown = False $hForm = GUICreate('MyGUI', 400, 200) $Label = GUICtrlCreateLabel('Saving data in progress...', 20, 74, 160, 14) $Progress = GUICtrlCreateProgress(20, 90, 360, 20) GUIRegisterMsg($WM_QUERYENDSESSION, 'WM_QUERYENDSESSION') GUIRegisterMsg($WM_ENDSESSION, 'WM_ENDSESSION') GUISetState() _WinAPI_SetProcessShutdownParameters(0x03FF) For $i = 0 To 100 _WinAPI_ShutdownBlockReasonCreate($hForm, 'This application is blocking system shutdown because saving critical data is in progress... ' & $i & '%') GUICtrlSetData($Label, 'Saving data in progress... ' & $i & '%') GUICtrlSetData($Progress, $i) Sleep(500) Next _WinAPI_ShutdownBlockReasonDestroy($hForm) If $Shutdown Then Exit EndIf Do Until GUIGetMsg() = -3 Func WM_QUERYENDSESSION($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $hForm If _WinAPI_ShutdownBlockReasonQuery($hForm) Then $Shutdown = True Return 0 EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_QUERYENDSESSION Func WM_ENDSESSION($hWnd, $Msg, $wParam, $lParam) Switch $hWnd Case $hForm If Not $wParam Then $Shutdown = False Return 0 EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_ENDSESSION My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JScript Posted April 28, 2011 Share Posted April 28, 2011 @Yashied Nice example!!! http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
adom Posted March 9, 2012 Share Posted March 9, 2012 Hello Friends, I played around with the script like that one from Yashied . Function with Vista Ultimate and Win7 pro. I got no result on Vista Home. Does anyone have an idea why is that?GreetingsAndrew Thanks! :bye: Greetings Andrew Link to comment Share on other sites More sharing options...
adom Posted March 11, 2012 Share Posted March 11, 2012 Found a new problem: If the Window which should receive the shutdown message and return 0 is minimized it does not block the the shut down. Thanks! :bye: Greetings Andrew Link to comment Share on other sites More sharing options...
Manko Posted March 12, 2012 Share Posted March 12, 2012 Found a new problem: If the Window which should receive the shutdown message and return 0 is minimized it does not block the the shut down.Make a gui, you dont show to user, so it wont be minimized, and let it receive shutdown request. If you need, you can have other guis for other stuff... 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 More sharing options...
Manko Posted March 12, 2012 Share Posted March 12, 2012 ...or rather register these messages BEFORE you create any GUI and see what happens. Autoit already have an invisible window, to handle some messages, created before any code in your script runs. 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 More sharing options...
adom Posted March 12, 2012 Share Posted March 12, 2012 Hi Manko, I have a hidden GUI already. But the problem is that Autoit generates a Trayicon by default what is OK in general. Now I figured out that regular registered messages are not affected. But when I use: GUIRegisterMsg(0x0011, 'WM_QUERYENDSESSION') ; GUIRegisterMsg($WM_ENDSESSION, 'WM_ENDSESSION') ; Set the highest shutdown priority for the current process to prevent closure the other processes. _WinAPI_SetProcessShutdownParameters(0x03FF) _WinAPI_ShutdownBlockReasonCreate($GuiTaskMngr, 'Taskmanager blockiert Shutdown.') and the Tray Icon ist clicked the _WinAPI_ShutdownBlockReasonCreate($GuiTaskMngr, 'Taskmanager blockiert Shutdown.') is not more in action. It seems that clicking on Tray Icon (not pause) breaks theat function. The scrict does not recognize anymore a WM_QUERYENDSESSION message. So even the mailfunction when Gui is minimized an have the reason in stealing focus and/or message by Tray Icon. But anyway I will try your proposal. Any idea on this? Greetings Andrew Thanks! :bye: Greetings Andrew Link to comment Share on other sites More sharing options...
adom Posted March 12, 2012 Share Posted March 12, 2012 Hi Manko, I tried to register GUIRegisterMsg(0x0011, 'WM_QUERYENDSESSION') before creating the GUI. No change of problem. Greetings Andrew Thanks! :bye: Greetings Andrew Link to comment Share on other sites More sharing options...
Manko Posted March 13, 2012 Share Posted March 13, 2012 I would guess there is some problem with how autoit handles messages or there is some problems with your script being tied to handle one thing when you would rather handle something else... ? The quick and dirty fix, (Not so dirty, but not the elegant "wisdom-enhancing" solution.) is to make a separate program for just dealing with stopping shutdown or similar, and do everything else in first program, communicating between them or starting/stopping as needed. We would like no visible GUI and NO trayicon: #NoTrayIcon /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 More sharing options...
adom Posted March 13, 2012 Share Posted March 13, 2012 Hi Manko, THX for your comment. Your both ideas are helpful. First I will try to fix it by using an event of the tray icon to switch back to the main GUI. If that doesnt help I will use #NoTrayIcon. Have a nice day and Thank you. Greetings Andrew Thanks! :bye: Greetings Andrew Link to comment Share on other sites More sharing options...
Manko Posted March 15, 2012 Share Posted March 15, 2012 Andrew, you should report status of your progress since others are reading your thread in search of answers. Your thread just got refered to as a "NO-Success", and I believe that might NOT be true... 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 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