Sign in to follow this  
Followers 0
Queener

Process kill loop

13 posts in this topic

#1 ·  Posted (edited)

I want to loop kill the process if it exist anytime when windows is up and running.

Here's what I have:

$file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0)

Kill()

Func Kill()

While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $PID = ProcessExists($line)
    ConsoleWrite ( "$line : " & $line & @Crlf )
    If $PID then ProcessClose($line)
Wend

Return

EndFunc

Now the problem is; once it reach the end of the text file line; it exitloop which the script stops.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites



Instead of using FileReadLine, use FileReadToArray and loop through the array instead, then you can just keep it in an endless loop.

$file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0)

Kill()

Func Kill()
    $aFile = FileReadToArray($file)

    While 1
        For $Loop = 0 To UBound($aFile)
            $PID = ProcessExists($aFile[$Loop])
            ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF)
            If $PID Then ProcessClose($aFile[$Loop])
        Next
    WEnd
EndFunc   ;==>Kill

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm getting

ERROR: FileReadToArray(): undefined function

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

It's in the latest version of AutoIt, as stated in my signature I only post code valid in what's currently available.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I got win 7 and yet has the latest version of autoit. Windows is 64-bit; not sure if that affects.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

I said the latest version of AutoIt, the version of Windows doesn't matter.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Sorry if I'm intruding, but what's wrong with simplicity?

While 1
  If ProcessExists (process.exe) Then
    ProcessClose (process.exe)
  EndIf
Sleep (100)
WEnd

I use this with an annoying "End Process" window I sometimes experience.


Meds.  They're not just for breakfast anymore. :'(

Share this post


Link to post
Share on other sites

asianqueen,

You need to download the latest version of autoit. However, try using _FileReadToArray() and see if that works.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok what allSystemsGo said, plus do not forget the  #include <File.au3> at beginning of your script

Edited by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

Sorry if I'm intruding, but what's wrong with simplicity?

While 1
  If ProcessExists (process.exe) Then
    ProcessClose (process.exe)
  EndIf
Sleep (100)
WEnd

I use this with an annoying "End Process" window I sometimes experience.

 

You did not read the OP. AsianQueen is looking to loop through an array of processes, and close them if active.


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

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Got the latest version of autoit.

$aFile[0] : GoogleUpdateSetup.exe
$aFile[1] : GoogleUpdate.exe
$aFile[2] : GoogleToolBarSetup[1].exe
"C:\Users\aq\Desktop\test.au3" (18) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$PID = ProcessExists($aFile[$Loop])
$PID = ProcessExists(^ ERROR
Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

Share this post


Link to post
Share on other sites

 

Instead of using FileReadLine, use FileReadToArray and loop through the array instead, then you can just keep it in an endless loop.

$file = FileOpen("\\server-pc\mystuff$\Others\ListOfProcess\killallprocesses.txt", 0)

Kill()

Func Kill()
    $aFile = FileReadToArray($file)

    While 1
        For $Loop = 0 To UBound($aFile)
            $PID = ProcessExists($aFile[$Loop])
            ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF)
            If $PID Then ProcessClose($aFile[$Loop])
        Next
    WEnd
EndFunc   ;==>Kill

asianqueen,

If you run the code above, what error do you get, if any?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Got it!!! :D

Kill()

Func Kill()

$aFile = FileReadToArray($file)

While 1
Local $list = Processlist()
For $i = 1 to $list[0][0]


        For $Loop = 0 To UBound($aFile) - 1
            $PID = ProcessExists($aFile[$Loop])
            ConsoleWrite("$aFile[" & $Loop & "] : " & $aFile[$Loop] & @CRLF)
            if StringRegExp($list[$i][0], $aFile[$Loop] & '.*$') then ProcessClose($List[$i][0])
    ;If $PID Then ProcessClose($aFile[$Loop])
Next
Next
WEnd
EndFunc   ;==>Kill

Thanks to everyone here. This is something I'm looking for. Very much appreciated.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")

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