K
K
KEKSOV2012-12-12 12:42:23
System administration
KEKSOV, 2012-12-12 12:42:23

Windows. How to get the PID of the last running process in a script?

Entry conditions.
1. Windows, starting with XP (if XP is a big problem, then you can do without it)
2. You can use only the tools built into the OS
3. You can use any script host, not only cmd.exe
Task.
There is a bat file like

@echo off
rem Этот файл может запускаться от имени ста пользователей одновременно
start /B notepad.exe rem Способ вызова notepad.exe можно изменить на любой другой, лишь бы работало
rem В этой строчке  нужно узнать PID только что запущенного notepad.exe

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VeMax, 2012-12-12
@KEKSOV

I don't know how in Windows XP, but on 7 it works:

Set oProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
oProcess.Create "Notepad.exe", , , intProcessID
WScript.Echo intProcessID

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question