To get process ID for batch file, need to set the name of
the process and the file extension.
Like on this example "LSM.EXE"
for /f
"tokens=2" %%i in ('tasklist | find "lsm.exe"') do set
PID=%%i
Token is set to 2
Output:
SET PID=828
for /f
"tokens=1" %%i in ('tasklist | find "lsm.exe"') do set
Process=%%i
Token is set to 1
Output:
set Process=lsm.exe
for /f
"tokens=3" %%i in ('tasklist | find "lsm.exe"') do set
Type=%%i
Token is set to 3
Output:
set Type=Services
See image below on why different token is specify it will
have different result:
LSM.EXE - is on 1st column
828 - process id is on 2nd column
Services - is on 3rd column
For PowerShell to get the Process ID is quite straight
forward:
To get process ID on PowerShell just need to set the process
name.
No need to set or specify ".exe".
get-process lsm |
select Id | ft -AutoSize
Cheers!!!
Comments
Post a Comment