Sign in to follow this  
Followers 0
Christopher Blue

How to have a script obtain it's own PID?

11 posts in this topic

For the purposes of my AutoIt killer script, I need to know how to find the PID of the script itself so that it may refrain from killing itself until the job is done.

Share this post


Link to post
Share on other sites



For the purposes of my AutoIt killer script, I need to know how to find the PID of the script itself so that it may refrain from killing itself until the job is done.

<{POST_SNAPBACK}>

:) I am wondering what the reason for the sudden explosion of post in the "Scripts and Scrapts" forum for regular support is.....

Must be 'Script and Scraps" day ....


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

Share this post


Link to post
Share on other sites

I must have posted this in the wrong place then. :) Would an admin please move it to v3 Support?

Share this post


Link to post
Share on other sites
Here is something interesting. I shall read more into it.

Share this post


Link to post
Share on other sites

Here is something interesting.  I shall read more into it.

<{POST_SNAPBACK}>

This should do it:

$pid = DllCall("kernel32.dll","int","GetCurrentProcessId")

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

Share this post


Link to post
Share on other sites

Thank you JdeB! I tried:

$pid = DllCall ( "kernel32.dll", "Int", "GetCurrentProcess", "ptr", "")

but it failed probably because I tried passing a parameter. I thought I had to because the DLLCall documentation doesn't list parameters as optional.

Share this post


Link to post
Share on other sites

Thank you JdeB!  I tried:

$pid = DllCall ( "kernel32.dll", "Int", "GetCurrentProcess", "ptr", "")

but it failed probably because I tried passing a parameter.  I thought I had to because the DLLCall documentation doesn't list parameters as optional.

<{POST_SNAPBACK}>

It is optional .....

i guess the helpfile should state:

DllCall ( "dll", "return type", "function"[, "type", param ])


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

Share this post


Link to post
Share on other sites

Sry, for this really late thread push ... but it's the only (one line) hint for realise "getting a program's own PID"

The code looks really good... but when I've the mini prog

$pid = DllCall("kernel32.dll","int","GetCurrentProcessId")
sleep(1000)
msgbox(0, "my_id", $pid)

the result is an empty msgbox :D

any idea?

Share this post


Link to post
Share on other sites

Wow, that was easy ... and I didn't find it on my own :o

However... thanks a lot! :D

Share this post


Link to post
Share on other sites

Wow, that was easy ... and I didn't find it on my own :o

However... thanks a lot! :D

Well to your defence it would have been the twelfth result if you search the helpfile for "pid" :D

BTW if you still want to know why your call to "GetCurrentProcessId" didn't work, then read the "Remarks"-section in the helpfile about DllCall or run this code, I think you will get it.

$pid = DllCall("kernel32.dll","int","GetCurrentProcessId")
sleep(1000)
MsgBox(0, "my_id", "PID from GetCurrentProcessId: " & $pid[0] & @CRLF  & "PID from @AutoItPID macro: " & @AutoItPID)

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