English 中文(简体)
检查某些窗户服务状况的通道
原标题:For loop for checking the state of certain windows services

services.txt contains:-

Plugplay
spooler
dhcp


我要检查文件<编码>服务.tx中规定的某些服务的状况。 我正在为此进行游说。

@echo off
for /f %%a IN ( type services.txt ) do call :chkservice %%a
goto :eof 

:chkservice 
sc query %a%

我拿不到这三处特定服务的产出,而是获得相当于“指挥编码”的三倍的产出。

为打字,我尝试核对变数<代码>a,使数值适当或未达到,并尝试这一代代码:-

@echo off
for /f %%a IN ( type services.txt ) do call :chkservice %%a
goto :eof

:chkservice
@echo on
echo %a%

该代码只显示<条码> 集合体<>和<条码>。 为什么不pl? 我认为这两个问题相互关联,但并不确定如何。

在这方面的任何帮助将受到高度赞赏。

问题回答

If you call a function your parameters are in %1,%2,...%n not in %a%.
The parameters of a for-loop are nearly invisble outside of that loop.

因此,您的法典应当考虑一下。

@echo off
for /f %%a IN ( type services.txt ) do call :chkservice %%a
goto :eof

:chkservice
echo %1
goto :eof




相关问题
complex batch replacement linux

I m trying to do some batch replacement for/with a fairly complex pattern So far I find the pattern as: find ( -name *.php -o -name *.html ) -exec grep -i -n hello {} + The string I want ...

How to split a string by spaces in a Windows batch file?

Suppose I have a string "AAA BBB CCC DDD EEE FFF". How can I split the string and retrieve the nth substring, in a batch file? The equivalent in C# would be "AAA BBB CCC DDD EEE FFF".Split()[n]

How to check which Operating System?

How can I check OS version in a batch file or through a vbs in an Windows 2k/2k3 environment ? You know ... Something like ... : "If winver Win2k then ... or if winver Win2k3 then ....

热门标签