如何获得一个windows服务的动态PID,然后kill它呢? [英] how to get the dynamic PID of a windows service and then kill it?

查看:307
本文介绍了如何获得一个windows服务的动态PID,然后kill它呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自己的Windows服务。我想获得服务的PID,然后在cmd中杀掉它。



哪个命令可以为我做这个?

tasklist 枚举进程:

pre> @echo off

for / ftokens = 2%% p in('tasklist / fiimagename eq your_svc.exe/ nh') do(
set PID = %% p

过程通过 taskkill

  taskkill / pid%PID%


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?

解决方案

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%

这篇关于如何获得一个windows服务的动态PID,然后kill它呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆