Sign in to follow this  
Followers 0
Ravel

Close A Process

7 posts in this topic

I am trying to create a script that will stay paused until a certain process becomes active (runs) and then close it. But after it closes... I would like to keep the script paused to close any future instances of the program that might become active. I have posted what i have so far below... does anyone know what i am doing wrong? If so could you show me what i am missing? Thanks in advance.

HotkeySet('{PAUSE}', 'Terminate')

while 1

If ProcessExists("sysLOAD_INI.pif") Then
    ProcessClose("sysLOAD_INI.pif")
Endif

Wend


Func Terminate()
    Exit

EndFunc

Share this post


Link to post
Share on other sites



Assuming that's the actual process name, then it looks fine. However, for the sake of your CPU, you might want to add a sleep in the While loop.

while 1

If ProcessExists("sysLOAD_INI.pif") Then
    ProcessClose("sysLOAD_INI.pif")
Endif
Sleep (20)
Wend

Share this post


Link to post
Share on other sites

If I understand you correctly, you want to wait until the first instance is ran, then if another instance is opened, then you want to close any other instances other than the original instance... you can try this... I'm not sure if you can mod maybe the _SingleTon() in beta to do this, but this worked when I tested it on notepad.

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


[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 I understand you correctly, you want to wait until the first instance is ran, then if another instance is opened, then you want to close any other instances other than the original instance... you can try this... I'm not sure if you can mod maybe the _SingleTon() in beta to do this, but this worked when I tested it on notepad.

Might want to try reading it again. It sure sounds to me like he just wants to wait around (forever) for a process to open, and immediately close it.. over and over.

Share this post


Link to post
Share on other sites

Might want to try reading it again. It sure sounds to me like he just wants to wait around (forever) for a process to open, and immediately close it.. over and over.

Yea thats exactly what i want it to do. Until I can figure out a way to get the program off the pc... i just want to keep it closed... (it is some spin off of aol).

Share this post


Link to post
Share on other sites

Might want to try reading it again. It sure sounds to me like he just wants to wait around (forever) for a process to open, and immediately close it.. over and over.

I would like to keep the script paused to close any future instances of the program that might become active.

That's the part that had me confused is why I said "If I understand correctly".

[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

Its cool I appreciate the help. Thanks.

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