how to get the dynamic PID of a windows service an

2019-07-30 00:56发布

问题:

I have an own windows service. I want to get the PID of the service and then kill it in the cmd.

Which command could do this for me?

回答1:

You could use tasklist to enumerate the processes:

@echo off

for /f "tokens=2" %%p in ('tasklist /fi "imagename eq your_svc.exe" /nh') do (
  set PID=%%p
)

and then kill the process via taskkill:

taskkill /pid %PID%


标签: cmd