Sign in to follow this  
Followers 0
Autoxics

Continuesly Prevent Another Instance Run Again While

12 posts in this topic

#1 ·  Posted (edited)

Hello good folks!

I have a problem,

lets say i have a script that is called test1.exe and when i run this script it searches for another process named test2.exe for example to see if it is active and if it is not active then test1.exe quits by itself

but if test2.exe is active then test1.exe script continues to run and executes its scriptfuntions that i want this test1.exe to do if/while test2.exe is running,so far i have manage to figure this part out,but i would like the script "test1.exe" to check and prevent a second copy of a process called test2.exe to run again if test2.exe

is allready running.

lets asume you run photoshop for example and you do you stuff in it and then somebody comes along and pushes the photoshop icon again to run it a second time while photoshop is allready running, and then it wont work couse photshop is allready running,

is this possible?

i know it sounds confusing

but i hope you get what i mean.

i have searched thrue the forum for this particular subject but i did not find a working solution for it

please help me!

Edited by Autoxics

Share this post


Link to post
Share on other sites



Have you looked at the ProcessExists() function?

What have you tried so far?

Share this post


Link to post
Share on other sites

Look up _SingleTon() either in the search function here or in the Beta Help file.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Have you looked at the ProcessExists() function?

What have you tried so far?

this is on a compiled script called test1.exe

$g_szVersion = "Notepad  1.1"
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)
HotKeySet("{HOME}", "start")
HotKeySet("{END}", "end")
Send("{HOME}", "start")
ProcessWaitClose("Notepad.exe")
ProcessWaitClose("Notepad.exe", 5)

I want test1.exe to prevent a second process of Notepad.exe for example or anyother file

lest say i run script1.exe and it looks to see if notepad is running and if i run notepad.exe again it will shutdown the second notepad.exe process that is trying to load

and i would like to do this by checking for a process name or a by the title of the window, but preferbly a process name, to prevent anyfile of a given name to run twize

Share this post


Link to post
Share on other sites

Look up _SingleTon() either in the search function here or in the Beta Help file.

i tried this

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

but i only got this to work with my own script1.exe name,

it only prevented the script1.exe to run again, but that is not what i am after i would like it to script1.exe to prevent another exe name to be running 2 times only one instance of another specific title or a process

Share this post


Link to post
Share on other sites

this is on a compiled script called test1.exe

$g_szVersion = "Notepad  1.1"
If WinExists($g_szVersion) Then Exit; It's already running
AutoItWinSetTitle($g_szVersion)
HotKeySet("{HOME}", "start")
HotKeySet("{END}", "end")
Send("{HOME}", "start")
ProcessWaitClose("Notepad.exe")
ProcessWaitClose("Notepad.exe", 5)

I want test1.exe to prevent a second process of Notepad.exe for example or anyother file

lest say i run script1.exe and it looks to see if notepad is running and if i run notepad.exe again it will shutdown the second notepad.exe process that is trying to load

and i would like to do this by checking for a process name or a by the title of the window, but preferbly a process name, to prevent anyfile of a given name to run twize

If it's another application other than yours, you could try something like this: http://www.autoitscript.com/forum/index.ph...ndpost&p=172318

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

If it's another application other than yours, you could try something like this: http://www.autoitscript.com/forum/index.ph...ndpost&p=172318

hello thank you very much, it seems like its working the way id like it to, but do i put it in the top of my script or where to make the rest of my script act as it should?

Global $FirstEXE = '', $Found = ''
While 1
    If ProcessExists('Notepad.exe') And $Found <> 1 Then 
        $FirstEXE = ProcessExists('Notepad.exe')
        $Found = 1
    EndIf

    Local $aProcList = ProcessList('Notepad.exe')
    If UBound($aProcList) - 1 > 1 Then
        For $icount = 1 To UBound($aProcList) - 1
            If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1])
        Next
    EndIf
    Sleep(10)
WEnd

Share this post


Link to post
Share on other sites

i would like this part of my code to still act as it suposed to even if i use the code i showed you that worked as i hoped for

Notepad is just an example here

ProcessWaitClose("Notepad.exe")
ProcessWaitClose("Notepad.exe", 5)

Share this post


Link to post
Share on other sites

I really don't know what your saying to be honest... Just make the script I made into a Function and leave it in a loop or something... As far as the ProcessWaitClose() the script freezes there, I would just do

If Not ProcessExists('exe') Then 
   ;Do Something
EndIf
That way your script can still be working (unless the pausing of the script is desired of course).


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Watch the total array of processes for a second "notepad.exe" and keep the PID of your process and close any other "notepad.exe"s. Or if you want to keep the script running one at a time, just look for more than one "test1.exe".

Share this post


Link to post
Share on other sites

Watch the total array of processes for a second "notepad.exe" and keep the PID of your process and close any other "notepad.exe"s. Or if you want to keep the script running one at a time, just look for more than one "test1.exe".

The script above does that kirby:
Global $FirstEXE = '', $Found = ''
While 1
    If ProcessExists('Notepad.exe') And $Found <> 1 Then
        $FirstEXE = ProcessExists('Notepad.exe')
        $Found = 1
    EndIf

    Local $aProcList = ProcessList('Notepad.exe')
    If UBound($aProcList) - 1 > 1 Then
        For $icount = 1 To UBound($aProcList) - 1
            If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1])
        Next
    EndIf
    Sleep(10)
WEnd

Takes note of the first instance, stores that PID in global Var and then any other instances it closes keeping the original open always.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I really don't know what your saying to be honest... Just make the script I made into a Function and leave it in a loop or something... As far as the ProcessWaitClose() the script freezes there, I would just do

If Not ProcessExists('exe') Then 
 ;Do Something
EndIf
That way your script can still be working (unless the pausing of the script is desired of course).

I got it working, i added the code that i told you worked for me,

this code, but i removed the "while 1" and the "WEnd" and the "Sleep(10))

and now it closed the second window of notepad as soon as i tried to execute another instance

but kept the first notepad window alive

Global $FirstEXE = '', $Found = ''
While 1
    If ProcessExists('Notepad.exe') And $Found <> 1 Then 
        $FirstEXE = ProcessExists('Notepad.exe')
        $Found = 1
    EndIf

    Local $aProcList = ProcessList('Notepad.exe')
    If UBound($aProcList) - 1 > 1 Then
        For $icount = 1 To UBound($aProcList) - 1
            If $aProcList[$icount][1] <> $FirstEXE Then ProcessClose($aProcList[$icount][1])
        Next
    EndIf
    Sleep(10)
WEnd

I allso added this code

in a nother function below in the rest of my script insted of adding it to the top where its froze my script and it did the job,

thank you so much for talking the time to help me out here!

Edited by Autoxics

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