-2

我需要接收名称等于“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 等。

4

1 回答 1

-1

avery_larry 的解决方案非常有效:我改变了

 if "%serviceName:~0,7%" equ %namedSqlServerServiceNameBeginning% (

if "!serviceName:~0,7!" equ %namedSqlServerServiceNameBeginning% (
于 2020-07-23T21:17:32.063 回答