0

我正在编写软件来扫描预定的服务并在它们停止时启动它们。不幸的是,一些服务名称有空格,所以如果我这样做:

for %%a in (MSSQLSERVER,SQLSERVERAGENT,Cardinal SPD Delivery Package Service,AuthenticationServiceHost,CommunicationService,CqiProcessorService,IISADMIN,MobileAutmationAgentService,MSMQ) do (

发生的情况是,当我这样做时,它将 Cardinal SPD Delivery 包视为三个独立的服务而不是一个

net start "%%a"

例如。我发现可行的替代方法是将服务放在文本文件中并执行

for /f %%a in (services.txt) do(

但我更喜欢第一种方法,因为它更干净。有什么建议么?

4

1 回答 1

0

要么双引号所有服务名称,而不是%%a在调用中引用:

for %%a in ("MSSQLSERVER","SQLSERVERAGENT","Cardinal SPD Delivery Package Service","AuthenticationServiceHost","CommunicationService","CqiProcessorService","IISADMIN","MobileAutmationAgentService","MSMQ") do (
net start %%a
)

%%a或仅对多个单词进行双引号,并在调用时删除引号:

for %%a in (MSSQLSERVER,SQLSERVERAGENT,"Cardinal SPD Delivery Package Service",AuthenticationServiceHost,CommunicationService,CqiProcessorService,IISADMIN,MobileAutmationAgentService,MSMQ) do (
net start %%~a
)
于 2012-11-09T18:34:21.853 回答