Jump to content

Process kill loop


Go to solution Solved by Queener,

Recommended Posts

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.")
Link to comment
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

Link to comment
Share on other sites

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.")
Link to comment
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

Link to comment
Share on other sites

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.")
Link to comment
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

Link to comment
Share on other sites

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

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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.")
Link to comment
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?

Link to comment
Share on other sites

  • Solution

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.")
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...