Jump to content
Sign in to follow this  
ghostofdeath

If process exists , process close

Recommended Posts

ghostofdeath

Basically, I want to check if a process exists from a process list that i have, and If one of them exists, close that, then return the loop :) my (noobish) code is that:

Dim $process[31]
$process[1]="wordpad.exe"
$process[2]="notepad.exe"
for $x=0 to 2
    msgbox(0, $x, $process[$x]&@LF)
Next
If ProcessExists($process) Then
    ProcessClose($process)
EndIf

PS:the msgbox is just to check the variables results

Thx~~

Edit:There's a way to put all the processes names "together", i mean dun put every process in a array value but in one line or variable separated by comma or anything else?

Edited by ghostofdeath

Share this post


Link to post
Share on other sites
Davo

First of all this code:

If ProcessExists($process) Then
    ProcessClose($process)
EndIf

There is also another method where you can store all the processes in an easy to edit text file, so just a basic .txt and then read each line of the txt and compare the line with the process that exists and close it if thats the case. Anway there is many ways it can be done there is also a processList function that lists all the current processes in an array and then you can sort that array for what exists and kill the processes you dont want running. If you are a bit more specific about your scenario I will probably be able to help you more.

Hope this helps. :)

Dave

Edited by Davo

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Share this post


Link to post
Share on other sites
ghostofdeath

There is also another method where you can store all the processes in an easy to edit text file, so just a basic .txt and then read each line of the txt and compare the line with the process that exists and close it if thats the case. Anway there is many ways it can be done there is also a processList function that lists all the current processes in an array and then you can sort that array for what exists and kill the processes you dont want running. If you are a bit more specific about your scenario I will probably be able to help you more.

Hope this helps. :)

Dave

Thx Dave.. the ubound command i didnt know, anyway i want to close all processes found on array , and there's a way to do the '.txt' file in like a '.anything' file? i write the file in notepad and then 'save as..' .anything, then fileread() ?

Share this post


Link to post
Share on other sites
SadBunny

Thx Dave.. the ubound command i didnt know, anyway i want to close all processes found on array , and there's a way to do the '.txt' file in like a '.anything' file? i write the file in notepad and then 'save as..' .anything, then fileread() ?

You can use _FireReadToArray if you want to read ANY file to an array. In this way you can write a plaintext file (file extension is up to you), then do something like the following:

Dim $a[1]
_FileReadToArray("c:\myfile",$a)
For $loop = 0 to $a[0] ; <-- The 0'th position of the array will tell how many lines are read
 ; <-- do whatever you want to the process
Next

Also... EXTENSIVE Process info (and a LOT of other computer information) can be retrieved easily by using the functions in CompInfo.au3: http://www.autoitscript.com/forum/index.ph...st&id=12096


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
ghostofdeath

EDIT: TROUBLE BOUND

You can use _FireReadToArray if you want to read ANY file to an array. In this way you can write a plaintext file (file extension is up to you), then do something like the following:

Dim $a[1]
_FileReadToArray("c:\myfile",$a)
For $loop = 0 to $a[0] ; <-- The 0'th position of the array will tell how many lines are read
 ; <-- do whatever you want to the process
Next

Also... EXTENSIVE Process info (and a LOT of other computer information) can be retrieved easily by using the functions in CompInfo.au3: http://www.autoitscript.com/forum/index.ph...st&id=12096

How can i use the func filereadtoarray? i dun have that func here Oo Edited by ghostofdeath

Share this post


Link to post
Share on other sites
Shevilie

EDIT: TROUBLE BOUND

How can i use the func filereadtoarray? i dun have that func here Oo

#include <Array.au3>


Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites
ghostofdeath

anyone knows if it force the process to close? like /f processkill dos command? command?

Share this post


Link to post
Share on other sites
Golbez

anyone knows if it force the process to close? like /f processkill dos command? command?

use the help file....

Share this post


Link to post
Share on other sites
herewasplato

anyone knows if it force the process to close? like /f processkill dos command? command?

It seems to force a close - if there is unsaved text in notepad or MS Word, it will close the process without prompting you to save the info...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

use the help file....

I did not see that question answered in the help file. Maybe I missed it or maybe you were thinking about the info discussed under WinClose/WinKill. Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Golbez

I did not see that question answered in the help file. Maybe I missed it or maybe you were thinking about the info discussed under WinClose/WinKill.

processclose will do what you want. its as if you went into the task manager and ended the process.

Share this post


Link to post
Share on other sites
SadBunny

A easier way to loop an array is like this

For $proces In $process
  If ProcessExists($proces) Then
    ProcessClose($proces)
  EndIf
Next
Except for that in this case it will have the same error that my code had, namely that it includes ALL elements, which you don't want for a _FileReadToArray result because the 0th element is useless for the rest of the function (in this case you will be trying to kill the process called "17" if you have 17 processes. If you change my For command to For $loop = 1 instead of For $loop = 0 like I did in my previous post, you will have the right list. This cannot be done in this case with For ... In ... with a _FileReadToArray output.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
ghostofdeath

I did it .. my final code is that:

#include <File.au3>
While 1
Opt("TrayIconHide",1)
Dim $process[1]
_FileReadToArray("prcss.dll",$process)
for $x=0 to 522
    If ProcessExists($process[$x]) Then
    ProcessClose($process[$x])
    EndIf
Next
WEnd

Share this post


Link to post
Share on other sites
herewasplato

try

Opt("TrayIconHide", 1)

#include <File.au3>

Dim $process[1]

While 1
    _FileReadToArray("prcss.dll", $process)
    For $x = 0 To 522
        If ProcessExists($process[$x]) Then
            ProcessClose($process[$x])
        EndIf
    Next
WEnd

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
ghostofdeath

Yea.. now its fine thanks for everybody :)

Share this post


Link to post
Share on other sites
herewasplato

I originally had "_FileReadToArray("prcss.dll", $process)" outside of the loop, but putting it inside the loop will allow you to edit/save/use the "text file" while the script is running.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
saltedpotato

you can make it as simple as this:

to close all process of notepad

while ProcessExists("notepad.exe")
     ProcessClose("notepad.exe")
WEnd

Edited by saltedpotato

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  

×