0

I'm trying to get the PID of a process on my system.

For example: when I run the query

sc querex Fax 

it returns the type, state, win32_exit code, PID, etc. How would I get the PID and turn it into a variable so I can use it later in the batch file?

2 Answers 2

1
FOR /f "tokens=1,2*delims=: " %%a IN ('sc queryex fax') DO IF "%%a"=="PID" SET /a pid=%%b

echo pid=%pid%
Sign up to request clarification or add additional context in comments.

Comments

0

This is very simple in PowerShell:

$service = Get-WmiObject Win32_Service -Filter "Name='Fax'"
$service.ProcessId  # Outputs the process ID of the service

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.