我需要接收名称等于“MSSQLSERVER”或以“MSSQL$”开头的进程的字符串。名称应以正斜杠 (/) 分隔。我正在尝试使用这样的脚本来做到这一点:
@echo off
set mssqlDependenties=
set defaultSqlServerServiceName="MSSQLSERVER"
set namedSqlServerServiceNameBeginning="MSSQL$"
setlocal enabledelayedexpansion
for /f "tokens=2" %%s in ('sc query state^= all ^| find "SERVICE_NAME: MSSQL"') do (
set serviceName=%%s
if "%%s" equ %defaultSqlServerServiceName% (
set mssqlDependenties=!mssqlDependenties!/%%s
)
if "%serviceName:~0,7%" equ %namedSqlServerServiceNameBeginning% (
set mssqlDependenties=!mssqlDependenties!/%%s
)
)
echo %mssqlDependenties%
但我收到一个错误:
The syntax of the command is incorrect.
mssqlDependenties 应包含 MSSQLSERVER/MSSQL$1/MSSQL$2/MSSQL$3 等。