chrispcall Posted May 16, 2013 Share Posted May 16, 2013 (edited) I have searched everywhere on this and it's a tough thing to search for. Search strings like "autoit ask user to close applications" and "autoit graceful app shutdown" have turned up very little. I'm writing a script to automate adding a profile to Outlook for a large user base. It will run on each user's machine and delete Outlook profiles and add a new one in and automate the creation and send user name and information etc. The problem is this: Outlook may be open on the user's machine. So I'm trying to either have a while loop (or similar) that checks if Outlook is open [winexists("Outlook")] and if the window is there, ask the user to close outlook. Then check again to ensure Outlook is closed until the user closes outlook. Once it's closed, continue on with the script. I can't quite figure out a loop to to do this. I tried something like this: while 1 if winexists("Outlook") then msgbox(16, "Outlook is open","Please close outlook and click 'OK'") else exitloop endif WEnd And that is not behaving correctly. // The first thing I tried before arriving on this solution is winclose("Outlook") The problem there is that sometimes that worked fine but sometimes, when I launched Outlook at the end of my script, Outlook would open saying it did not shut down correctly and asks the user for additional input. This obviously is bad for my scripting attempts. It usually works, but sometime it does now. I'm assuming this is from Autoit killing the outlook process vs a graceful shutdown from the user. Any help would be greatly appreciated! (P.S. Sorry for the longs post. Just wanted to be clear...) Thanks in advance, Chris Edited May 16, 2013 by chrispcall Link to comment Share on other sites More sharing options...
Solution Nessie Posted May 16, 2013 Solution Share Posted May 16, 2013 Try this: Do If ProcessExists("outlook.exe") Then MsgBox(0, "Ops!", "Please close Outlook!") EndIf Until Not ProcessExists("outlook.exe") I don't have outlook installed here, so i don't know if the process name is "outlook.exe". If not change with the right process name. Hi! My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 16, 2013 Moderators Share Posted May 16, 2013 (edited) You can check for the process as Nessie suggests above. For the close, I have always leaned more toward manipulating the object rather than just killing the process; personal preference. $oMail = ObjGet("", "Outlook.Application") $oMail.Quit Edit: Or completely using the object model, and skipping the process lookup: $oMail = ObjGet("", "Outlook.Application") If IsObj($oMail) Then $oMail.Quit Else MsgBox(0, "", "Object does not exist") EndIf Edited May 16, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
chrispcall Posted May 16, 2013 Author Share Posted May 16, 2013 Thank you both for your replies! For future scripts, I will try JLogan's code. since I'm short on testing time right now (I would need a good bit dedicated to trying this a lot of times to ensure that I am not still randomly (and rarely) seeing the Outlook closing incorrectly message after using your new object method. As for Nessie's response, it is working great. Thanks! How would I go about exiting the script if the user clicks the cancel button on my msgbox? (It has 'OK' and 'Cancel' buttons) I.E msgbox(16, "","") I saw some examples using switch and select but I can't get them to play nicely with the "if" statement in your code. Do If ProcessExists("outlook.exe") Then ; Checks to see if Outlook is open and asks the user to exit Outlook if it is. $box = MsgBox(16, "Outlook is open", "Please close Outlook and click 'OK'") select case $box = 2 exit EndIf Until Not ProcessExists("outlook.exe") This is throwing an error: "EndIf" statement with no matching "If" statement.: Endif Thanks again! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 16, 2013 Moderators Share Posted May 16, 2013 Look in the help file under Msgbox, it will show you how to close if they click cancel (hint: if msgbox = <number assigned to cancel> then exit) As for your error, you don't have an EndSelect in there to close the Select statement. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
chrispcall Posted May 16, 2013 Author Share Posted May 16, 2013 Your're the man! Thanks. For future people with this problem, here is my working code: Do If ProcessExists("outlook.exe") Then ; Checks to see if Outlook is open and asks the user to exit Outlook if it is. $box = MsgBox(1, "Outlook is open", "Please close Outlook and click 'OK'") select case $box = 2 exit EndSelect EndIf Until Not ProcessExists("outlook.exe") Link to comment Share on other sites More sharing options...
Nessie Posted May 16, 2013 Share Posted May 16, 2013 Glad to help you My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
guinness Posted May 17, 2013 Share Posted May 17, 2013 Try not to use processclose if you can, opt for sending a WM_CLOSE message via winclose. Search the forum on how to get a handle from a PID. 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...
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