Sign in to follow this  
Followers 0
islandspapand

Kill running processes. With Array. HELP!!!!

8 posts in this topic

#1 ·  Posted (edited)

Hello wonderful autoit forum. I need some help with some array commands.

I want to create a program which lists all running processes to an array, then removes all processes that i want to save from that array, and then closes the remaining processes.

I am guessing that it should look something like this but i can't get it to work.

It may have something to do with the ""For $i = 0 To $avArray2D[0][1]"" command,

but i don't know how to parse it, as my expertice is very novice. I have writen the processes to be saved as 2d & 1d array since i don't know which i should use.

Hope someone can help :)

#include <Array.au3>
;######Processes to Save 2D Array#################
Global $avArray2D[29][2] = [ _
["smss.exe", ""], _
["csrss.exe", ""], _
["wininit.exe", ""], _
["winlogon.exe", ""], _
["services.exe", ""], _
["lsass.exe", ""], _
["lsm.exe", ""], _
["svchost.exe", ""], _
["spoolsv.exe", ""], _
["svchost.exe", ""], _
["SeaPort.exe", ""], _
["taskhost.exe", ""], _
["dwm.exe", ""], _
["explorer.exe", ""], _
["sysprep.exe", ""], _
["igfxpers.exe", ""], _
["SearchIndexer.exe", ""], _
["svchost.exe", ""], _
["taskmgr.exe", ""], _
["svchost.exe", ""], _
["LMS.exe", ""], _
["ccSvcHst.exe", ""], _
["cmd.exe", ""], _
["conhost.exe", ""], _
["audiodg.exe", ""], _
["tasklist.exe", ""], _
["WmiPrvSE.exe", ""], _
["Menu.exe", ""], _
["nircmd.exe", ""]]
;######Processes to Save #################
Global $avArray[29]
$avArray[0] = "smss.exe"
$avArray[1] = "csrss.exe"
$avArray[2] = "wininit.exe"
$avArray[3] = "winlogon.exe"
$avArray[4] = "services.exe"
$avArray[5] = "lsass.exe"
$avArray[6] = "lsm.exe"
$avArray[7] = "svchost.exe"
$avArray[8] = "spoolsv.exe"
$avArray[9] = "svchost.exe"
$avArray[10] = "SeaPort.exe"
$avArray[11] = "taskhost.exe"
$avArray[12] = "dwm.exe"
$avArray[13] = "explorer.exe"
$avArray[14] = "sysprep.exe"
$avArray[15] = "igfxpers.exe"
$avArray[16] = "SearchIndexer.exe"
$avArray[17] = "svchost.exe"
$avArray[18] = "taskmgr.exe"
$avArray[19] = "svchost.exe"
$avArray[20] = "LMS.exe"
$avArray[21] = "ccSvcHst.exe"
$avArray[22] = "cmd.exe"
$avArray[23] = "conhost.exe"
$avArray[24] = "audiodg.exe"
$avArray[25] = "tasklist.exe"
$avArray[26] = "WmiPrvSE.exe"
$avArray[27] = "Menu.exe"
$avArray[28] = "nircmd.exe"
$list = ProcessList()
_ArrayDisplay($list, "Running Processes")
_ArrayDisplay($avArray, "Processes To Save")
_ArrayDisplay($avArray2D, "Processes To Save 2D")
For $i = 0 To $avArray2D[0][1]
_ArrayDelete($list,$avArray2D)
Next
_ArrayDisplay($list, "Processes To Kill")
ProcessClose($list)

thank in advance

Edited by islandspapand

Share this post


Link to post
Share on other sites



islandspapand,

Try something like this (not tested)

Global $avArray[29]
$avArray[0] = "smss.exe"
$avArray[1] = "csrss.exe"
$avArray[2] = "wininit.exe"
$avArray[3] = "winlogon.exe"
$avArray[4] = "services.exe"
$avArray[5] = "lsass.exe"
$avArray[6] = "lsm.exe"
$avArray[7] = "svchost.exe"
$avArray[8] = "spoolsv.exe"
$avArray[9] = "svchost.exe"
$avArray[10] = "SeaPort.exe"
$avArray[11] = "taskhost.exe"
$avArray[12] = "dwm.exe"
$avArray[13] = "explorer.exe"
$avArray[14] = "sysprep.exe"
$avArray[15] = "igfxpers.exe"
$avArray[16] = "SearchIndexer.exe"
$avArray[17] = "svchost.exe"
$avArray[18] = "taskmgr.exe"
$avArray[19] = "svchost.exe"
$avArray[20] = "LMS.exe"
$avArray[21] = "ccSvcHst.exe"
$avArray[22] = "cmd.exe"
$avArray[23] = "conhost.exe"
$avArray[24] = "audiodg.exe"
$avArray[25] = "tasklist.exe"
$avArray[26] = "WmiPrvSE.exe"
$avArray[27] = "Menu.exe"
$avArray[28] = "nircmd.exe"
$list = ProcessList()
; this will compare what is running againt the save list and close anything not in the save list
local $close = true
For $i = 0 To ubound($list) - 1
 for $j = 0 to ubound($avArray) - 1
  if $list[$i] = $avArray[$j] then $close = False
 Next
 if $close then processclose($list[$i])
 $close = True
next

Caution: I did not test this code, just an example of how it might be done!!!!

You may want to read some of the many excellent articles about arrays on this forum and wiki...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks allot kylomas

i have just testet your code. and i get a error.

i will start investigating arrays on this forum and wiki but i was woundering if you could answer a question for me.

The thing i do not understand in this code is: For$i= 0 Toubound($list)- 1 :

am i saying that it sould look from the start of the array to the end. $i=0 is the start and ubound($list) is the end. so when i enter $list[$i] the [$i]

make the search for start to end of the array?

sorry if my formulation is bad. i will try to re-explain. If you dont understand me.

@error:

C:UsersjackraDesktopTEST.au3 (39) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

if $list[$i] = $avArray[$j] then $close = False

if ^ ERROR

Share this post


Link to post
Share on other sites

Okay i have been trying some different things and the scripts is finally almost doing what i want it to do.

My problem now is that it dos not remove all the processes from my SAVE LIST from the Processes list array.

any thought on what i am doing wrong?

#include <File.au3>
#include <array.au3>
Global $avArray[30]
$avArray[0]="audiodg.exe"
$avArray[1]="ccSvcHst.exe"
$avArray[2]="cmd.exe"
$avArray[3]="conhost.exe"
$avArray[4]="csrss.exe"
$avArray[5]="dwm.exe"
$avArray[6]="explorer.exe"
$avArray[7]="explorer.exe"
$avArray[8]="igfxpers.exe"
$avArray[9]="LMS.exe"
$avArray[10]="lsass.exe"
$avArray[11]="lsm.exe"
$avArray[12]="Menu.exe"
$avArray[13]="nircmd.exe"
$avArray[14]="SeaPort.exe"
$avArray[15]="SearchIndexer.exe"
$avArray[16]="services.exe"
$avArray[17]="smss.exe"
$avArray[18]="spoolsv.exe"
$avArray[19]="svchost.exe"
$avArray[20]="svchost.exe"
$avArray[21]="svchost.exe"
$avArray[22]="svchost.exe"
$avArray[23]="sysprep.exe"
$avArray[24]="taskhost.exe"
$avArray[25]="tasklist.exe"
$avArray[26]="taskmgr.exe"
$avArray[27]="wininit.exe"
$avArray[28]="winlogon.exe"
$avArray[29]="WmiPrvSE.exe"

$list = ProcessList()
_ArrayDelete($list, 0)
_ArrayDelete($list, 0)
_ArrayDelete($list, 0)
_ArrayDisplay($list,"Running Processes")
For $x = 1 To UBound($avArray) -1
_ArraySort($list)
_ArrayDelete($list,$avArray[$x])
Next
_ArrayDisplay($list,"Processes Left After Removel")
MsgBox(0,"Closing","Processes left are about to close")
For $i = 0 To UBound($list) -1
;ProcessClose($List[$i][0])
Next

Thanks in advance

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

you need to change your logic, because you now delete Array entry 1 which will make entry 2 the new entry 1 in the array.

So currently you remove entries 1 when $x =1 and then Entry 3 when $x=2 etc....

It will work when you reverse the for next loop:

For $x = UBound($avArray) - 1 to 1 step -1
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Is there a reason why you're killing some of these processes? For example DWM.EXE is probably pretty important if you're running an Aero theme. Plus several of those probably can't be killed by normal means due to them being protected processes.

You might want to see what those processes do before you go and try and kill them because you're computer will be unstable without several of them, and others can't be killed, and still others will restart themselves after you've killed them.


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

islandspapand,

Sorry, forgot that processlist returns a 2x array...

This code was tested and works

Global $avArray[29]
$avArray[0] = "smss.exe"
$avArray[1] = "csrss.exe"
$avArray[2] = "wininit.exe"
$avArray[3] = "winlogon.exe"
$avArray[4] = "services.exe"
$avArray[5] = "lsass.exe"
$avArray[6] = "lsm.exe"
$avArray[7] = "svchost.exe"
$avArray[8] = "spoolsv.exe"
$avArray[9] = "svchost.exe"
$avArray[10] = "SeaPort.exe"
$avArray[11] = "taskhost.exe"
$avArray[12] = "dwm.exe"
$avArray[13] = "explorer.exe"
$avArray[14] = "sysprep.exe"
$avArray[15] = "igfxpers.exe"
$avArray[16] = "SearchIndexer.exe"
$avArray[17] = "svchost.exe"
$avArray[18] = "taskmgr.exe"
$avArray[19] = "svchost.exe"
$avArray[20] = "LMS.exe"
$avArray[21] = "ccSvcHst.exe"
$avArray[22] = "cmd.exe"
$avArray[23] = "conhost.exe"
$avArray[24] = "audiodg.exe"
$avArray[25] = "tasklist.exe"
$avArray[26] = "WmiPrvSE.exe"
$avArray[27] = "Menu.exe"
$avArray[28] = "nircmd.exe"
$list = ProcessList()

; this will compare what is running againt the save list and close anything not in the save list

local $close = true
For $i = 1 To ubound($list,1) - 1
    for $j = 0 to ubound($avArray) - 1
        if $list[$i][0] = $avArray[$j] then $close = False
    Next
    if $close then
        processclose($list[$i][0])
        msgbox(0,'','Closing ' & $list[$i][0])
    endif
    $close = True
next

However, as BrewnamNH said, are you sure that this is what you want to do?

Also, follow the logic. This script will attempt to close all that is NOT on the safe list.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

First of all thnx Jos for the explanation.

BrewnamNH. The reason i want to kill as many processes as possible is that after the processes are killed i want to run som test on the pc for about 10 min and after that the pc will be shutdown. and the processes that restart themselves after been killed they must just restart.the protected processes must also just run.

kylomas thank you so much for the help. You just made my day.I will try it strait away

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