批处理脚本获取服务状态 [英] batch script get service status

查看:482
本文介绍了批处理脚本获取服务状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在w7上,我想使用psservice接收服务的状态,因为我想稍后在远程计算机上进行此操作.

On w7 I want to receive the status of a service using psservice, since I want to do this on a remote computer later.

我尝试首先使批处理脚本在本地计算机上工作.

I try to get the batch script working on local machine first.

我有两个问题:第一个问题是"D:/PsService.exe查询服务器"将查询所有包含名称服务器"的服务.我只想查询一项特定服务(在本示例中名为服务器".

I have two issues: First issue is that "D:/PsService.exe query Server" will query ALL serviced containing the name "Server". I only want to query one specific service (in this example named "Server".

另一个更大的问题是我的批处理脚本根本不起作用.它只是死了"(CMD窗口不执行暂停命令便立即关闭,这使得调试非常困难.)

The other, bigger issue, is that my batch script are not working at all. It just "dies" (the CMD window immediately closes without execute the pause command, which make it extremely hard to debug).

我想将服务的状态存储在一个变量中,稍后将用它来比较示例(如果%Status%EQ"RUNNING").

I want to store the status of the service in a variable, which I gonna use later to compare example (IF %Status% EQ "RUNNING").

到目前为止,我的代码:

My code so far:

FOR /F token=3 %%i IN ('D:/PsService.exe query Server 2> NUL | find /I "STATE"') DO   ( SET Status=%%i )
echo %Status%
pause

为什么CMD会死掉,我在做什么错了?

Why does the CMD just die and what am I doing wrong?

推荐答案

以下内容将为您服务

   @ECho off
   for /F "tokens=3 delims=: " %%H in ('D:/PsService.exe query "SERVICE" ^| findstr "        STATE"') do echo %%H

这篇关于批处理脚本获取服务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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