Process ids

  • Thread starter Thread starter Steve Rainbird
  • Start date Start date
S

Steve Rainbird

Is it possible to get the process id of a program that you have just run in
a bat file?
 
If only one instance of that program is running, the following bat file
could prove useful to you to determine the PID of that process:

---
@echo off
set PID=
for /F "tokens=2 delims=," %%A in ('tasklist /nh /fo csv /fi "imagename eq
notepad.exe"') do set PID=%%A
echo pid=%PID%
---

Note that "for...do set PID=%%A" is in the same line (the post may
wrap-around). Replace notepad.exe with the executable name of the program
for which you want to find the process id.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
Chirag said:
If only one instance of that program is running, the following bat file
could prove useful to you to determine the PID of that process:

---
@echo off
set PID=
for /F "tokens=2 delims=," %%A in ('tasklist /nh /fo csv /fi "imagename eq
notepad.exe"') do set PID=%%A
echo pid=%PID%
---

Note that "for...do set PID=%%A" is in the same line (the post may
wrap-around). Replace notepad.exe with the executable name of the program
for which you want to find the process id.

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html

Chirag,

Thanks for that but the reason I want to know the pid is that there may be
many running.

I want the program to create a print file which contains its pid so that the
script can then print that file after it has finished.
 
Back
Top