Board logo

标题: [系统相关] 【已解决】批处理如何通过服务名称取得服务的pid? [打印本页]

作者: zhaokeistc    时间: 2015-6-25 11:09     标题: 【已解决】批处理如何通过服务名称取得服务的pid?

本帖最后由 zhaokeistc 于 2015-6-25 21:39 编辑

不是进程是服务,可以做到吗
作者: zhaokeistc    时间: 2015-6-25 11:27

服务的pid和进程的pid是一样的      或者也可以逆推     从进程的pid获取服务名称
作者: pcl_test    时间: 2015-6-25 11:39

  1. wmic SERVICE where name="服务名" get ProcessId
复制代码

作者: zhaokeistc    时间: 2015-6-25 13:19

本帖最后由 zhaokeistc 于 2015-6-25 13:20 编辑

回复 3# pcl_test


    非常感谢,再追问一下如果想把这个id值设置成一个变量需要怎么做

这是执行命令的输出结果

C:\Users\Administrator>wmic SERVICE where name="LazyStopService" get ProcessId
ProcessId
2020
作者: pcl_test    时间: 2015-6-25 15:17

回复 4# zhaokeistc
  1. @for /f %%a in ('wmic SERVICE where name^="LazyStopService" get ProcessId^|findstr "[0-9]"') do @echo,%%a
  2. @pause
复制代码

作者: zhaokeistc    时间: 2015-6-25 21:38

回复 5# pcl_test


   太感谢了,不过用%%a不行   我换成%a就可以了
作者: DAIC    时间: 2015-6-25 21:51

回复 6# zhaokeistc


    5楼的那种语法是需要把代码保存成 xxx.bat 来执行的
作者: zhaokeistc    时间: 2015-6-28 15:18

回复 7# DAIC


    哦,怪不得,我是直接在cmd里测试的,多谢




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2