01101 Posted March 28, 2010 Share Posted March 28, 2010 (edited) Hi everyone,Windows 7 has one annoying thing. When shutting down the pc it always asks me if I want to force to close the following programs, such as Opera browser or Outlook 2007. I didn't have this problem in vista as such, because at the moment if I don't close these programs before shutting down the pc they basically crash when I want to open them after I started the system later...So what I need now is a button which will close the most vulnerable programs which in my case are Opera and M$ Outlook 2007. I want to close them, wait few seconds and then turn the pc off.I will need help with this as I don't know where to start and I will be grateful for that.Thanks in advance. Edited March 28, 2010 by 1101 Link to comment Share on other sites More sharing options...
JohnOne Posted March 28, 2010 Share Posted March 28, 2010 Your starting place is the Autoit helpfile you want to begin with Shutdown ProcessClose AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 Your starting place is the Autoit helpfileyou want to begin with ShutdownProcessCloseThanks for that, but instead of ProcessClose I need to use WinClose as processclose is killing the process and I don't want that since shutting down the pc is doing this already ;P Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 Can't edit my post... I'm trying with WinClose and I have no luck. I've tried with few different windows. ie PSPad, Microsoft Word, Firefox etc.. For example I used: WinClose("[ACTIVE]","") Presumably according to the help file this script should close active window, but it doesn't. It brings the "closing windows" window with a list of options, log off, sleep, shutdown etc.. and maybe I do something wrong? Link to comment Share on other sites More sharing options...
JohnOne Posted March 28, 2010 Share Posted March 28, 2010 So what you basically want to do, is automate the closing down of Opera and outlook ? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 So what you basically want to do, is automate the closing down of Opera and outlook ?Yes, after opera and outlook are closed wait few seconds and then shut down the pc. Link to comment Share on other sites More sharing options...
JohnOne Posted March 28, 2010 Share Posted March 28, 2010 Well this works for me $hwnd = WinGetHandle("Opera") WinClose($hwnd) Sleep(2000) You just need to do it for each thing you want to close, including any dialogue boxes that might appear during its closing process. Or you may have to Send() ControlSend() something to confirm a dialogue box. And of course add the Shutdown() function AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 (edited) Well this works for me $hwnd = WinGetHandle("Opera") WinClose($hwnd) Sleep(2000) You just need to do it for each thing you want to close, including any dialogue boxes that might appear during its closing process. Or you may have to Send() ControlSend() something to confirm a dialogue box. And of course add the Shutdown() function Thanks for this, but it doesn't work sometimes and brings the "closing windows" window up. It closes opera, firefox fine, but it doesn't close microsoft outlook. I tried both names, together and separately and no luck :/ Edited March 28, 2010 by 1101 Link to comment Share on other sites More sharing options...
JohnOne Posted March 28, 2010 Share Posted March 28, 2010 I dont use outlook so I cant try myself does this "closing windows" window require you to press a button to complete the closing of outlook ? If so you need to use the windowinfo tool of autoit to get info from it in order to automate the selecting of the button ? if you can paste the info from the tool about the window, I maybe can help you. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GEOSoft Posted March 28, 2010 Share Posted March 28, 2010 What happens if you use Opt("WinTitleMatchMode", 2) at the top of your script? Or something like (not tested) $aProc = ProcessList() For$i = 1 To Ubound($aProc) -1 If StringRegExp($aProc[$i][0],".*Outlook|Opera.*") Then ProcessClose($aProc[$i][1]) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 (edited) What happens if you use Opt("WinTitleMatchMode", 2) at the top of your script? Or something like (not tested) $aProc = ProcessList() For$i = 1 To Ubound($aProc) -1 If StringRegExp($aProc[$i][0],".*Outlook|Opera.*") Then ProcessClose($aProc[$i][1]) Thanks, but first I will read more what these things mean lol I dont use outlook so I cant try myself does this "closing windows" window require you to press a button to complete the closing of outlook ? If so you need to use the windowinfo tool of autoit to get info from it in order to automate the selecting of the button ? if you can paste the info from the tool about the window, I maybe can help you. I meant this window: and no, i can only turn pc off, log off, restart, sleep, hibernate. edit:this script worked with outlook:Opt("WinTitleMatchMode", 2) $hwnd = WinGetHandle("Microsoft Outlook") WinClose($hwnd) Sleep(2000) When it was just "Outlook" it brought Opera up (??) Do I add Sleep(2000) after every program or can it be added at the end of all scripts? Edited March 28, 2010 by 1101 Link to comment Share on other sites More sharing options...
GEOSoft Posted March 28, 2010 Share Posted March 28, 2010 $aWindows = WinList() If IsArray($aWindows) Then For $i = 1 To UBound($aWindows) - 1 If StringRegExp($aWindows[$i][0], "(?i).*Opera|outlook|fireFox.*") Then MsgBox(0, "Result " & $i, $aWindows[$i][0], 2) EndIf Next EndIf Where I have the MsgBox() you can close the process instead and then after the loop is finished use ShutDown(), it's in the help file. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 (edited) $aWindows = WinList() If IsArray($aWindows) Then For $i = 1 To UBound($aWindows) - 1 If StringRegExp($aWindows[$i][0], "(?i).*Opera|outlook|fireFox.*") Then MsgBox(0, "Result " & $i, $aWindows[$i][0], 2) EndIf Next EndIf Where I have the MsgBox() you can close the process instead and then after the loop is finished use ShutDown(), it's in the help file. I don't know how to do it or what parameters to use. I've replaced the msgbox() with processclose without any parameters as I have no idea what I'm doing :/ The error windows comes up. The example that JohnOne has posted does work, but only when all programs that are mentioned inside the script are running and if one of them isn't running I get the "closing windows" window... which closes the SciTEditor and the autoit help file - probably the last active window.. Perhaps I could use something like "use only if running/open" or "something" but as I say I can't get this language Opt("WinTitleMatchMode", 2) $hwnd = WinGetHandle("Microsoft Outlook") WinClose($hwnd) Sleep(2000) $hwnd = WinGetHandle("Opera") WinClose($hwnd) Sleep(2000) $hwnd = WinGetHandle("Firefox") WinClose($hwnd) Sleep(2000) Edited March 28, 2010 by 1101 Link to comment Share on other sites More sharing options...
JohnOne Posted March 28, 2010 Share Posted March 28, 2010 try this Opt("WinTitleMatchMode", 2) If WinExists("Microsoft Outlook") Then $hwnd = WinGetHandle("Microsoft Outlook") WinClose($hwnd) Sleep(2000) EndIf If WinExists("Opera") Then $hwnd = WinGetHandle("Opera") WinClose($hwnd) Sleep(2000) EndIf If WinExists("Firefox") Then $hwnd = WinGetHandle("Firefox") WinClose($hwnd) Sleep(2000) EndIf AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
01101 Posted March 28, 2010 Author Share Posted March 28, 2010 This seems working just fine. I will test it for few days. Thank you all involved. Opt("WinTitleMatchMode", 2) Sleep(2000) If WinExists("Microsoft Outlook") Then $hwnd = WinGetHandle("Microsoft Outlook") WinClose($hwnd) Sleep(250) EndIf If WinExists("Opera") Then $hwnd = WinGetHandle("Opera") WinClose($hwnd) Sleep(250) EndIf If WinExists("Firefox") Then $hwnd = WinGetHandle("Firefox") WinClose($hwnd) Sleep(250) EndIf If WinExists("iTunes") Then $hwnd = WinGetHandle("iTunes") WinClose($hwnd) Sleep(250) EndIf Shutdown(0) 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