Jump to content

Advise: What the efficient way to close a running application


coucou
 Share

Recommended Posts

Hi,

I mainly using AutoIt scripts to unatttended install Windows and Applictions, and I have always difficulties to close a running applications. The AutoIt functions i'm using: ProcessClose, ProcessWaitClose, WinKill, WinClose without success. For sure i'm misusing these functions.

As last resort, i'm using the taskkill.exe and/or nircmd.exe utilities. Moreover, it happens that i have to split my AutoIt script, when one of the utilities here above is between 2 scripts.

Do anyone can advise how/what the most efficient way to close a running application.

Regards

coucou

Link to comment
Share on other sites

Hi,

I mainly using AutoIt scripts to unatttended install Windows and Applictions, and I have always difficulties to close a running applications. The AutoIt functions i'm using: ProcessClose, ProcessWaitClose, WinKill, WinClose without success. For sure i'm misusing these functions.

As last resort, i'm using the taskkill.exe and/or nircmd.exe utilities. Moreover, it happens that i have to split my AutoIt script, when one of the utilities here above is between 2 scripts.

Do anyone can advise how/what the most efficient way to close a running application.

Regards

coucou

Use a loop to keep checking until it ends. Like as follows...
While ProcessExists("Process.exe")
    ProcessClose("Process.exe")
WEndoÝ÷ Øìµæ¡ø(x()ßx­z­éò¢ç(ºWm¯+(ëax,h¥j»h¶¢YhÂ)àjëh×6For $i = 1 To 10 Step 1
    If ProcessExists("Process.exe") Then
        ProcessClose("Process.exe")
    Else
        ExitLoop
    EndIf
Next

I hope one of the above examples will help send you on your way.

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Do anyone can advise how/what the most efficient way to close a running application.

Hi coucou,

Efficient depends on the application.

Using WinClose or clicking the finish button is the good way to close an application as it can do it's save settings and cleanup routine.

ProcessWaitClose does not close the process, but instead waits for it to close, so is fine to use so your script does not continue on before the process ends.

ProcessClose, WinKill, Taskkill and Nircmd would be a last resort to closing an application as it does kill the process immediately without giving the application time to save settings and cleanup. If you get a pest program like a browser open during install then ProcessClose maybe good to use as you just want to kill it anyway.

During the RunOnce period, you may need to use WinClose twice to close an explorer window as it tends to ignore the 1st WinClose.

:P

Link to comment
Share on other sites

TNX gentlemen for yr help

@JSThePatriot: i'll test yr suggestion and let you know furthere

@MHz:

Efficient depends on the application.

Using WinClose or clicking the finish button is the good way to close an application as it can do it's save settings and cleanup routine.

I do NOT need to save any settings. In fact, during the RunOnce period i 'm installing among other softwares, Cyberlink Medi@show and I have success installing silently. The problem is i have to upgrade it with 2 patches.

The patch1 when it finish the upgrade, it launch Cyberlink Medi@show. I have to close Medi@show, close patch1, then launc patch2.

Here my script:

RunWait("MediaShow300728.exe")
sleep(500)

;Extract winrar archive patch1 to  c:\Program FilesDir\Cyberlink\
RunWait("MedShow_Patch1_arc.exe")
sleep(500)
;Run patch1
Run(@ProgramFilesDir & "\Cyberlink\MedShow_Patch1.exe")

;Close Mediashow
WinWaitActive("Cyberlink Medi@Show", "")
ProcessClose("MediaShow.exe")

;Close Patch1
WinWaitActive("MediaShow_Patch300728", "")
ControlClick("MediaShow_Patch300728", "", "Button3")

;Run patch2
RunWait("PatchRetail1306.exe")

$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
RunWait("MeddiaShow_FR.exe")
RunWait("PhotoNow100915_FR.exe")

EndIf

Everything goes well except the ProcessClose.

Any suggestion will be welcome.

BTW, What command to delete patch1 from c:\Program FilesDir\Cyberlink\ after its installation?

Regards

coucou

Link to comment
Share on other sites

Try closing the retunred PID from Run.

Opt('TrayIconDebug', 1)

RunWait("MediaShow300728.exe")
Sleep(500)

;Extract winrar archive patch1 to  c:\Program FilesDir\Cyberlink\
RunWait("MedShow_Patch1_arc.exe")
Sleep(500)
;Run patch1
$pid = Run('"' & @ProgramFilesDir & '\Cyberlink\MedShow_Patch1.exe"')

;Close Mediashow
WinWait("Cyberlink Medi@Show")
ProcessClose($pid)

;Close Patch1
WinWait("MediaShow_Patch300728")
ControlClick("MediaShow_Patch300728", "", "Button3")

;Run patch2
RunWait("PatchRetail1306.exe")

$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
    RunWait("MeddiaShow_FR.exe")
    RunWait("PhotoNow100915_FR.exe")

EndIf

Using WinWait should be enough as active windows are not needed within the script.

:P

Link to comment
Share on other sites

Try closing the retunred PID from Run.

Opt('TrayIconDebug', 1)

RunWait("MediaShow300728.exe")
Sleep(500)

;Extract winrar archive patch1 to  c:\Program FilesDir\Cyberlink\
RunWait("MedShow_Patch1_arc.exe")
Sleep(500)
;Run patch1
$pid = Run('"' & @ProgramFilesDir & '\Cyberlink\MedShow_Patch1.exe"')

;Close Mediashow
WinWait("Cyberlink Medi@Show")
ProcessClose($pid)

;Close Patch1
WinWait("MediaShow_Patch300728")  [color="#FF0000"]<--- STOP HERE[/color]
ControlClick("MediaShow_Patch300728", "", "Button3")

;Run patch2
RunWait("PatchRetail1306.exe")

$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
    RunWait("MeddiaShow_FR.exe")
    RunWait("PhotoNow100915_FR.exe")

EndIf

Using WinWait should be enough as active windows are not needed within the script.

:P

Tested,

Cyberlink Medi@Show doesn't close.

The amazing thing is, the patch1 is closed.

Do the $pid is correct??? for the moment it contain patch1 and NOT Mediashow.exe. Isn't it???

Regards

coucou

Link to comment
Share on other sites

Tested,

Cyberlink Medi@Show doesn't close.

The amazing thing is, the patch1 is closed.

Do the $pid is correct??? for the moment it contain patch1 and NOT Mediashow.exe. Isn't it???

Regards

coucou

As shown in the code by MHz, $PID = Run of the Mediashow_patch1.exe. If you need another PID then duplicate the sample that MHz created for you.

Also have you tested my methods above?

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Also have you tested my methods above?

JS

YES It WORKS :P (yous just forgot Then after If)

RunWait("MediaShow300728.exe")
sleep(500)

;Extract winrar archive patch1 to  c:\Program FilesDir\Cyberlink\
RunWait("MedShow_Patch1_arc.exe")
sleep(500)
;Run patch1
Run(@ProgramFilesDir & "\Cyberlink\MedShow_Patch1.exe")

;Close Mediashow
WinWaitActive("Cyberlink Medi@Show", "")
For $i = 1 To 10 Step 1
    If ProcessExists("MediaShow.exe") Then
        ProcessClose("MediaShow.exe")
    Else
        ExitLoop
    EndIf
Next

;Close Patch1
WinWaitActive("MediaShow_Patch300728", "")
ControlClick("MediaShow_Patch300728", "", "Button3")

;Run patch2
RunWait("PatchRetail1306.exe")

$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
RunWait("MeddiaShow_FR.exe")
RunWait("PhotoNow100915_FR.exe")

EndIf

Maybe MHz can improve this script with "ProcessWaitClose("patch1.exe") in order wait for MediaShow.exe process closing then Patch1 will be closed

Many TNX to you gentlemen

coucou

Link to comment
Share on other sites

YES It WORKS :P (yous just forgot Then after If)

RunWait("MediaShow300728.exe")
sleep(500)

;Extract winrar archive patch1 to  c:\Program FilesDir\Cyberlink\
RunWait("MedShow_Patch1_arc.exe")
sleep(500)
;Run patch1
Run(@ProgramFilesDir & "\Cyberlink\MedShow_Patch1.exe")

;Close Mediashow
WinWaitActive("Cyberlink Medi@Show", "")
For $i = 1 To 10 Step 1
    If ProcessExists("MediaShow.exe") Then
        ProcessClose("MediaShow.exe")
    Else
        ExitLoop
    EndIf
Next

;Close Patch1
WinWaitActive("MediaShow_Patch300728", "")
ControlClick("MediaShow_Patch300728", "", "Button3")

;Run patch2
RunWait("PatchRetail1306.exe")

$Lang = RegRead("HKEY_CURRENT_USER\Control Panel\International", "sLanguage")
If $Lang = "FRA" Then
RunWait("MeddiaShow_FR.exe")
RunWait("PhotoNow100915_FR.exe")

EndIf

Maybe MHz can improve this script with "ProcessWaitClose("patch1.exe") in order wait for MediaShow.exe process closing then Patch1 will be closed

Many TNX to you gentlemen

coucou

My mistake on the Then. I just typed it in, simple error.

I am glad you got it resolved. I am going to go above and fix my code in case someone else may need it.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...