PID (Process ID), of a running program.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

PID (Process ID), of a running program.

Post by Albireo » 26 Nov 2014, 09:20

Hi!
I want to get the process ID of a running program (as possible to find in the task manager).
I have tested

Code: Select all

Process Exist, Label32.exe
PID := ErrorLevel
MsgBox 64, Row %A_LineNumber% -> %A_ScriptName%, PID = %PID%
But I only got "0" as result

//Jan

Bkid
Posts: 31
Joined: 13 Jun 2014, 12:19

Re: PID (Process ID), of a running program.

Post by Bkid » 26 Nov 2014, 09:26

I tried that exactly script with notepad and it returned the PID just fine. You're 100% sure Label32.exe is running at the time?

Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

Re: PID (Process ID), of a running program.

Post by Albireo » 27 Nov 2014, 07:15

You have right!
The prossess doesn't exist
When the program is running, I can see in the task manager (win7) .: Label32.exe *32
If I use the code below (the code right now)

Code: Select all

SetTitleMatchMode 2
Run c:\windows\system32\schtasks.exe /run /tn Skyltprogram,, MAX, LabelPID  ; Run Label32.exe from the scheduled task right now

Sleep 3000

Process Exist, Label32.exe   ; In the task manager stands "Label32.exe *32" (win7 without "")
PID := ErrorLevel
MsgBox 64, Row %A_LineNumber% -> %A_ScriptName%, PID = %PID% `nLabelPID = %LabelPID%
I have change the command

Code: Select all

Sleep 3000
to

Code: Select all

WinWait ahk_pid Label32.exe
But it doesn't work, the program "hung" on the "WinWait" command.

Albireo
Posts: 1778
Joined: 16 Oct 2013, 13:53

Re: PID (Process ID), of a running program.

Post by Albireo » 27 Nov 2014, 10:33

Now I found a solution.

Run the following command.

Code: Select all

RunWait c:\windows\system32\schtasks.exe /run /tn Skyltprogram,, MAX
It works!

//Jan

Post Reply

Return to “Ask for Help (v1)”