如何测试服务是否在命令行中运行 [英] How to test whether a service is running from the command line

查看:104
本文介绍了如何测试服务是否在命令行中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够查询服务是否从Windows批处理文件运行。我知道我可以使用:


  

SC查询服务名称


不过,这种转储出一些文字。我真正想要的是为它设置错误级别环境变量,以便我可以采取的行动。

你知道一个简单的方法可以让我做到这一点?

更新

感谢迄今答案。我担心解析文本的解决方案可能无法在非英语操作系统上工作。有谁知道解决的办法,还是我将不得不硬着头皮写一个控制台程序得到这个权利。


解决方案

  SC查询服务名称|找到跑

I would like to be able to query whether or not a service is running from a windows batch file. I know I can use:

sc query "ServiceName"

but, this dumps out some text. What I really want is for it to set the errorlevel environment variable so that I can take action on that.

Do you know a simple way I can do this?

UPDATE
Thanks for the answers so far. I'm worried the solutions that parse the text may not work on non English operating systems. Does anybody know a way around this, or am I going to have to bite the bullet and write a console program to get this right.

解决方案

sc query "ServiceName" | find "RUNNING"

这篇关于如何测试服务是否在命令行中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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