我正在编写软件来扫描预定的服务,如果它们被停止则启动它们。不幸的是,有些服务名称有空格,所以如果我这样做:
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(
但我更喜欢第一种方法,因为它更清洁。有什么建议吗?
答案 0 :(得分: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
)