user1039304
user1039304

Reputation: 465

how to get the dynamic PID of a windows service and then kill it?

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?

Upvotes: 2

Views: 3829

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200453

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%

Upvotes: 6

Related Questions