Jump to content

My Second Script


Recommended Posts

hey guys this is my second script, what this program will be is, it forces a process close on processes based on a database of known baddies

this time i have used notepad and calc for my testing

i have also added a total processes killed messagebox, the coding works fantastic

however, each process requires its own section of code

here is my code:

$ProcessName = "notepad.exe"
$ProcessesKilled = 0

If ProcessExists($ProcessName) Then
    ProcessClose($ProcessName)
    MsgBox(0, "Process killed",$ProcessName & " has been killed")
    $ProcessesKilled = $ProcessesKilled + 1
Else
    MsgBox(0, "Not Running",$ProcessName & " is not running")
EndIf

$ProcessName = "calc.exe"

If ProcessExists($ProcessName) Then
    ProcessClose($ProcessName)
    MsgBox(0, "Process killed",$ProcessName & " has been killed")
    $ProcessesKilled = $ProcessesKilled + 1
Else
    MsgBox(0, "Not Running",$ProcessName & " is not running")
EndIf

MsgBox(0, "Total Processes killed", $Processeskilled & " were killed")

i have a few questions, which i need to ask here because the help file wont launch for some reason

1. is there a way to end the processes, using ony one section of my code, based on a textfile, which this reads each line and treats each line as a processName

and loops until it comes accross a blank line?

2. is it possible to write each process killed into a seperate txt file, each one to its own seperate line?

3. is it possible to trace each process to its source and as such delete it and anything related?

i am thinking of releasing this with 3 options, that is:

1. Diagnostic Mode. diagnostic mode checks to see if any proccesses from the process database are running and writes them to a seperate txt file, so if it is an inexperienced user using this they could send this to a technical support forum,

2. Clean out Mode. if it is an experienced user, they can then use this if they want to close each process or not, how? a dialog box with a yes or no button will appear, displays a dialog with a yes or no button to close each process, requires running Diagnostic mode, this will read the txt file from the diagnostic and includes a browse function to locate the file if the user has renamed it

3. Kill Mode. Kills each process in the database and displays a msg with the amount of processes killed, does not include writing to a seperate text file

i am not entirely sure how to go about this ppl, i have GUI creation figured out i just dont know how to set commands to the buttons made

Thanks in advance :D

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Well, you could use a for loop to loop through an array like so

for $i = 1 to $processArray[0]
     KillProcess($processArray[$i])
next

for the array in the first place do something like

$processArray = _FileToArray('ProcessList.txt")

or something of the like.

Link to comment
Share on other sites

how exactly do i put that code in?

i keep getting an error : unknown function name for a fumction name thats even in the help file

_FileReadToArray

any ideas how to get this to work, i am newbie still

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

thankyou i could work off this

is there a way i could set my database txt file to this? i am beginning to hate arrays

or give an example of a working array that reads lines from a txt file and converts them to a variable

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

ok its ready to go

heres v1

i am not using any arrays for a database text file, until i figure out how

features:

-lightweight, can be run from anywhere, even a usb

-friendly messages with intructions

-only kills suspect programs but each kill is also recorded to a txt file

only contains 1 virus def at the moment: an MSN Virus that none of the antivirus companies know about, one i came accross by mistake while chatting to a friend

virus def contains info on all the attributes and a possible solution so you guys may have better luck removing it than i did

coming up in V2:

- more lightweight, with the addition of a txt file as the database of running programs to look for

- more virus defs

how to use:

1. Extract the zip file to anywhere you wish

2. Run KILL-IT.exe and follow the intructions, currently, instructions only pop up if it finds anything

KILL_IT_antivirus.zip

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

ok now to my Diagnosis option which i am still working on

here is the code

#Include <File.au3>

Dim $sProcesses = 'calc.exe|notepad.exe|wmplayer.exe'
Dim $aProcesses = StringSplit($sProcesses, '|')

_FileCreate("KILLED.txt")

$ProcessesKilled = 0

For $i = 1 To $aProcesses[0]
     While ProcessExists($aProcesses[$i])
         FileWriteLine("KILLED.txt", $aProcesses[$i])
         Sleep(20)
     WEnd
 Next

how do i make it so that it only lists each process once?

it keeps listing and listing and listing while that program is running (Notepad)

this is the result of my test

notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe
notepad.exe

see?

its getting stuck on the one program, how do i stop that from happening?

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

Hi,

In your previous code the while loop just continues while a process exists and does nothing apart from log to your file.

Run your previous code, and while it is running manually close or kill notepad, it should move on to the next process

in the list, but then the result will be the same as with notepad.

So try this minor modification to your code.

Dim $sProcesses = 'calc.exe|notepad.exe|wmplayer.exe'
  Dim $aProcesses = StringSplit($sProcesses, '|')
  Dim $hLog = FileOpen("KILLED.txt",9)
  Dim $ProcessesKilled = 0
  
  For $i = 1 To $aProcesses[0]
      IF ProcessExists($aProcesses[$i]) THEN
          WHILE ProcessExists($aProcesses[$i])
        ; Dont forget the process kill/close code;)
              ProcessClose($aProcesses[$i])
              FileWriteLine($hLog, $aProcesses[$i] &" Terminated.")
              $Processeskilled += 1
          WEND
      ELSE
          FileWriteLine($hLog,$aProcesses[$i] &" Not Found.")
      ENDIF
  Next
  
  FileClose($hLog)
  MsgBox(0,@USERNAME,"Total close attempts: "& $ProcessesKilled)

This is sloppy code (mine) that does not take into account the fact that processclose is a light way of terminating a process.

Plus it does not actually check if the process has been closed, it just assumes.

Btw, stick with arrays, they are worth their weight in gold in the future. :D

Vlad

Edited by Mobius

wtfpl-badge-1.png

Link to comment
Share on other sites

Thankyou, but i do not wish any of the processes to close for my Diagnosis option, only to see that the process exists, then moves on to the next one, so a slight modification is needed, a way to tell it that the process is closed after recognizing that it is active, but then moves on to the next one without closing it

is that possible? again i thankyou for your help

Intermediate AutoIt/Autohotkey User

Link to comment
Share on other sites

You can use ProcessList() and then iterate while checking each against the processes in the $aProcesses.

Example:

Dim $sProcesses = 'calc.exe|notepad.exe|wmplayer.exe'
Dim $aProcesses = StringSplit($sProcesses, '|')
Dim $aProcList = ProcessList()
Dim $hFile = FileOpen('KILLED.txt', 1)

$ProcessesKilled = 0

For $i = 1 To $aProcList[0][0]
    For $j = 1 To $aProcesses[0]
        If $aProcList[$i][0] = $aProcesses[$j] Then
            FileWrite($hFile, 'Process name: ' & $aProcList[$i][0] & @TAB & '|' & @TAB & 'Process ID: ' & _
                $aProcList[$i][1] & @CRLF)
            ExitLoop
        EndIf
    Next
    Sleep(20)
Next
 
FileClose($hFile)

Edit: No need #include <File.au3>.

Edited by Authenticity
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...