Sign in to follow this  
Followers 0
Showtime2kX

Background process not closing

17 posts in this topic

Hi,

I have several AutoIT scripts that run installers for me (CCleaner, Malwarebytes, etc.). If I stop and close the installer before it finishes, it closes, but the AutoIT script continues to run in the background.

I don't want to add in a timeout on my WinWaitActive commands because, to deal with computers that might be slow and are lagging, I didn't want that to accidentally time out when I'm running these on PCs that I'm repairing.

Is there some other way besides using a timeout, to make the background process of the script close when I close the installer that it's running?

Thanks in advance,

Matt

Share this post


Link to post
Share on other sites



Without seeing the code it's impossible to tell what you are talking about and where the problem is.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

If you need to run an installer and automate the install process by using AutoIt I wouldn't allow the user to cancel the install process.

Use function BlockInput to block all user input by keyboard and mouse.

Or - the way I prefer - use the command line switches of the software to do a silent install.

The switches for CCleaner can be found here.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Here is an example from my Malwarebytes installer:

$MalwareBytes = "\Applications\Installers\Security Software\Anti-Malware\Malwarebytes\Newer Versions\malwarebytes.exe"

Run($MalwareBytes)
Sleep(2000)
WinWaitActive("Select Setup Language", "English")
Sleep(2000)
WinActivate("Select Setup Language", "English")
Sleep(2000)
ProcessWait("malwarebytes.exe")
ControlClick("Select Setup Language", "OK", "TNewButton1")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "&Next >")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton1")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "License Agreement")
ControlClick("Setup - Malwarebytes Anti-Malware", "I &accept the agreement", "TNewRadioButton1")
Sleep(2000)
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton2")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Please read the following important information before continuing.")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton2")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Select Destination Location")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton3")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Select Start Menu Folder")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton4")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Select Additional Tasks")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Next >", "TNewButton4")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Ready to Install")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Install", "TNewButton4")
Sleep(2000)
WinWaitActive("Setup - Malwarebytes Anti-Malware", "Click Finish to exit Setup.")
Send("{TAB}")
Send("{SPACE}")
Send("{TAB}")
Send("{TAB}")
Send("{SPACE}")
ControlClick("Setup - Malwarebytes Anti-Malware", "&Finish", "TNewButton4")
Sleep(2000)
ProcessClose("malwarebytes.exe")
Sleep(3000)

Exit

And it isn't "to stop a user" from cancelling the install. It is in case I accidentally ran it and needed to stop the install before it finishes.

Share this post


Link to post
Share on other sites

The return value of Run is the PID of the process that was launched.

So you could always check if the process you startet still exists:

If Not ProcessExists($PID) Then Exit

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks.

Where within the code should I place that If statement?

Share this post


Link to post
Share on other sites

Guess!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

.. Before every statement that would "hang" your script. That means before every WinWait* function or every other function that will wait forever when the install process is no longer available.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Certainly should add a bunch of extra lines to the code. I imagine there is no "cleaner" way.

Thanks.

Share this post


Link to post
Share on other sites

There is: AdLibregister. Will post an example later.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

This should work too:

$PID = Run(".....")
AdlibRegister("_CheckProcess", 250)

; Your code goes here

Func _CheckProcess()
    If Not ProcessExists($PID) Then exit
EndFunc
Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I imagine there is no "cleaner" way.

There is a much "cleaner" way, use the silent switches as Water suggested in Post 4, and get your script down to this:

ShellExecuteWait("CCleaner.exe", "/S")

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Glad to be of service :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Mark, it is helpful

Share this post


Link to post
Share on other sites

Mark, it is helpful

Please refrain from doing this. If you want to 'mark' the post for later use e.g. when you get home, then use another method please instead of unnecessarily bumping.

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0