Sign in to follow this  
Followers 0
Rorax

Start script, check if script is running, if it is, kill it, and continue

6 posts in this topic

Basically I have a script that can get stopped before completing.

$g_szVersion = "Scanner"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)

But this only does so that the script doesnt start twice. But I want to kill it before it starts if its running.

$g_szVersion = "Scanner"
If WinExists($g_szVersion) Then 
ProcessClose("Autoit3.exe")
ProcessClose("wiaacmgr.exe")
Exit
EndIf
AutoItWinSetTitle($g_szVersion)

That works, but it doesnt check if its the correct script to close. It just closes the first Autoitv3 script it finds. Is there a way to set the processname of a script or a better way to close it if it knows its running while making ure its the correct peocess?

Thanks in advance

Share this post


Link to post
Share on other sites



Basically I have a script that can get stopped before completing.

$g_szVersion = "Scanner"
If WinExists($g_szVersion) Then Exit
AutoItWinSetTitle($g_szVersion)

But this only does so that the script doesnt start twice. But I want to kill it before it starts if its running.

$g_szVersion = "Scanner"
If WinExists($g_szVersion) Then 
ProcessClose("Autoit3.exe")
ProcessClose("wiaacmgr.exe")
Exit
EndIf
AutoItWinSetTitle($g_szVersion)

That works, but it doesnt check if its the correct script to close. It just closes the first Autoitv3 script it finds. Is there a way to set the processname of a script or a better way to close it if it knows its running while making ure its the correct peocess?

Thanks in advance

If you compile your script, then the process name will be something like YourScript.exe, and much easier to identify and kill. The name will only be AutoIT3.exe if you are running it uncompiled.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can add the following line to the begining of your script

If UBound(ProcessList(@ScriptName)) > 2 Then Exit

OR you can look for a better solution at the help file for called _SINGLETON

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Damn I'm stupid, didnt know it changed processname after compilation..oops guess I learn something new everyday. Thanks for helping me out! Appreciate it

Share this post


Link to post
Share on other sites

You may want to look closer at FAQ 14. There is a illogical difference between recognition of a window title and the concept of closing a process name because of the title.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I know it was a while since you replied, but anyway I checked FAQ 14

14. How can I make sure only one copy of my script is run?

The easiest way is to rename the title of the hidden AutoIt window when your script first starts. Then in the same script check for that window title existing - if it does then another copy of the script is running.

; Place at the top of your script

$g_szVersion = "My Script 1.1"

If WinExists($g_szVersion) Then Exit ; It's already running

AutoItWinSetTitle($g_szVersion)

; Rest of your script goes here

And I'm using

$g_szVersion = "TSFAutoSkanner"
If WinExists($g_szVersion) Then
    If ProcessExists("wiaacmgr.exe") then ProcessClose("wiaacmgr.exe")
    If ProcessExists(@Scriptname) then ProcessClose(@ScriptName)
EndIf
    AutoItWinSetTitle($g_szVersion)

But I dont see the illogical difference (not native english speaker so not 100% sure I got the right definition)

Basically, it checks if TSFAutoSkanner exists, if it does it closes the process. I cant just use If ProcessExists since the process will start the second the script does.

Havent tried to use _Singleton or the Ubound part since it worked with the code above. But is there a chance that it will get messed up? I realise it will get messed up by the slim chance of a windowtitle being TSFAutoSkanner but other then that?

Regards,

Rorax

Edited by Rorax

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