Sign in to follow this  
Followers 0
cal

Finding PID Number of a running process?

11 posts in this topic

1. I'd like to know the PID number of running scripts. Ideally an array of filename and PIDs would be perfect but ProcessList only seems to work on the exe.

2. I'd also like to know the PID number of the script making the call. but I've been unable to see a way to find it. Is there a function that I've missed that will return this?

What I've seen so far is that.

$list = ProcessList("autoit3.exe")
for $i = 1 to $list[0][0]
  msgbox(0, $list[$i][0], $list[$i][1])
next

Always lists my scripts in the order that I started them. But I can't always be sure that the last one in the list is going to be the one I want.

Since the above is true this will kill any and all scripts if started by itself manually as a separate file as the last PID in the array will be itself.

$list = ProcessList("autoit3.exe")
for $i = 1 to $list[0][0]  
  ProcessClose($list[$i][1])
next

This is nice but not really what I'm after.

A side note on the above. Nice to have handy if you accidentally create a script that calls another copy of itself that calls another copy of itself that....... you get the picture. It will kill any script started before itself but not the ones the bad script called as this is getting started. Starting it several times in a row did the trick. (no, I did not want to just reboot to fix it)

I'm aware that I can compile the script and therefor have a unique process name that I can scan for but I'd rather not have to do that if I can avoid it.

The needed info is there somewhere because If I hover my mouse over the icons in the tray the filename is there. Perhaps I need a command thats in the Beta? (I'm using the standard version at the moment)

This all started off when I needed to do a wait for either of a couple of windows to appear before doing something, windows that cannot be predicted because they depend on what I'm doing as well as other programs. So its not a case of a simple if or case statement. I thought at first that AdlibEnable might help but Either I'm using it wrong or it does not do what I thought.

Calling a second script from the first using run took care of the issue as the run command returns the PID of the script its starting. This way it can be closed when no longer needed. As a bonus if both scripts are waiting then there is no cpu power being used.

Now however I need more flexibility and numbers 1 and 2 at the top of this post would fill in what I want nicely if It can be done.

One use of this would be a function at the top of a script that checks to see if its already running, kills it without killing itself, and leave itself in memory. That way you can edit a script your working on and just hit F5 to run it and the new version replaces the old version in memory. I have no idea how many times I've forgotten to stop the old script of something I'm working on before running the new version then wonder why nothing changed. :)

Share this post


Link to post
Share on other sites



straight out of the help and don't need the beta

$list = ProcessList()
for $i = 1 to $list[0][0]
  msgbox(0, $list[$i][0], $list[$i][1])
next

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I'm sure it does what I want but I don't understand much of it. I see that it returns "name, Pid, and memory" Hopefully thats file name and not process name but I can't understand enough of what he is doing to be sure. Still, it looks interesting.

My thought process so far...

- Objget function is undefined. what? Hmm not in help either. Must be beta. yep found it.

- OK install beta.

- more undefined stuff and a parsing error. Hmm lets try to understand what he is actually doing before continuing.

- looks at what object are and so forth. OK looks promising, whats winmgmts

- ah, built in objects in W2000 and XP, problem, this is a NT box.

- lets try it on my W2000 laptop.... autoit3 not installed, unforgivable.....OK installed, Still same errors. OK, must be something I'm not doing properly.

- \root\CIMV2" is a default location according to google. I can't seem to find that on my laptop. why not.

- remotely checks home XP box. Nope don't see that there either. I thought it was part of w2000 and XP. Perhaps not. I'll look at it more next week. The long weekend is nearly here.

********* if it does help.... left gafrost know 

I will. Once I can understand what he did. Funny, I'm sure I read that post when I was searching but just skipped over it since I did not have a clue what was being done. I guess I'll dig into it more next week.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

straight out of the help and don't need the beta

Well, Actually I already had that much. Thats the process name. Not the name of the script that created the process.

Doing that just gives an array of processes with the pids.

It gives me

autoit3.exe 299

autoit3.exe 307

as an example instead of what I need for example.

startup.au3 299

start2.au3 307

Does your script that I was pointed to above give the "autoit3.exe" name or would it be returning "startup.au3"?

edit..... whats the "warning" 0% with some boxes under my name in the fourm. Some sort of new guy thing untill I get more posts?

Edited by cal

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Well, Actually I already had that much.  Thats the process name.  Not the name of the script that created the process.

Doing that just gives an array of processes with the pids.

It gives me

autoit3.exe 299

autoit3.exe 307

as an example instead of what I need for example.

startup.au3 299

start2.au3 307

Does your script that I was pointed to above give the "autoit3.exe" name or would it be returning "startup.au3"?

edit..... whats the "warning" 0% with some boxes under my name in the fourm. Some sort of new guy thing untill I get more posts?

<{POST_SNAPBACK}>

You won't get:

startup.au3 299

start2.au3 307

being they are not executables, the autoit3.exe used to start them is the process in memory:

if you compile those two files and run them then you will get

startup.exe 299

start2.exe 307

Now if you want the pid of the autoit.exe that started startup.au3 then it would be something like

$pid[2][2]

$pid[0][0] = 'starup.au3'

$pid[0][1] = Run("autoit.exe startup.au3")

$pid[1][0] = 'start2.au3'

$pid[1][1] = Run("autoit.exe start2.au3")

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

You won't get:

startup.au3 299

start2.au3 307

being they are not executables, the autoit3.exe used to start them is the process in memory:

if you compile those two files and run them then you will get

startup.exe 299

start2.exe 307

Now if you want the pid of the autoit.exe that started startup.au3 then it would be something like

$pid[2][1]

$pid[0][0] = 'starup.au3'

$pid[0][1] = Run("autoit.exe startup.au3")

$pid[1][0] = 'start2.au3'

$pid[1][1] = Run("autoit.exe start2.au3")

<{POST_SNAPBACK}>

I do believe you mean...

$pid[2][2]

$pid[0][0] = 'starup.au3'
$pid[0][1] = Run("autoit.exe startup.au3")

$pid[1][0] = 'start2.au3'
$pid[1][1] = Run("autoit.exe start2.au3")

:):evil:

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I'm sure it does what I want but I don't understand much of it.  I see that it returns "name, Pid, and memory"  Hopefully thats file name and not process name but I can't understand enough of what he is doing to be sure.  Still, it looks interesting.

My thought process so far...

- Objget function is undefined.  what? Hmm not in help either.  Must be beta.  yep found it.

- OK install beta.

- more undefined stuff and a parsing error.  Hmm lets try to understand what he is actually doing before continuing.

- looks at what object are and so forth.  OK looks promising, whats winmgmts

- ah,  built in objects in W2000 and XP, problem, this is a NT box.

- lets try it on my W2000 laptop.... autoit3 not installed, unforgivable.....OK installed, Still same errors.  OK, must be something I'm not doing properly.

- \root\CIMV2" is a default location according to google.  I can't seem to find that on my laptop. why not.

- remotely checks home XP box.  Nope don't see that there either.  I thought it was part of w2000 and XP.  Perhaps not.  I'll look at it more next week.  The long weekend is nearly here.

I will.  Once I can understand what he did.  Funny, I'm sure I read that post when I was searching but just skipped over it since I did not have a clue what was being done.  I guess I'll dig into it more next week.

<{POST_SNAPBACK}>

http://msdn.microsoft.com/library/default....i_providers.asp

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I do believe you mean...

$pid[2][2]

$pid[0][0] = 'starup.au3'
$pid[0][1] = Run("autoit.exe startup.au3")

$pid[1][0] = 'start2.au3'
$pid[1][1] = Run("autoit.exe start2.au3")

:):evil:

JS

<{POST_SNAPBACK}>

Yep, thanks, "long day at work"

Gary

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Yep, thanks, "long day at work"

Gary

<{POST_SNAPBACK}>

Shew, I am right there with ya. :)

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

One use of this would be a function at the top of a script that checks to see if its already running, kills it without killing itself, and leave itself in memory.  That way you can edit a script your working on and just hit F5 to run it and the new version replaces the old version in memory.  I have no idea how many times I've forgotten to stop the old script of something I'm working on before running the new version then wonder why nothing changed.  :)

<{POST_SNAPBACK}>

I'm quoting myself to answer it.

I missed something obvious and can answer this part of my questions without using pids at all.

using the following code at the top of the script solves at least this one thing.

; ensure this copy is the running one.
$g_szVersion = "Startup Script"
If WinExists($g_szVersion) Then WinClose($g_szVersion)
AutoItWinSetTitle($g_szVersion)

where $g_szVersion is something unique to each script.

Its nearly straight out of the help pages. A very slightly modified form of the example code to exit the running script if its already running. This closes the old copy and lets the new copy run.

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