【发布时间】:2017-05-07 12:22:22
【问题描述】:
我一直在尝试将以下两个命令的输出转换为变量,以便可以在批处理文件中使用它们,但是我没有运气:
WMIC /namespace:\\root\SecurityCenter2 PATH AntiVirusProduct WHERE (displayName="Emsisoft Anti-Malware" or displayName="Emsisoft Internet Security") GET displayName /value
WMIC /namespace:\\root\SecurityCenter2 PATH AntiVirusProduct WHERE (displayName="Emsisoft Anti-Malware" or displayName="Emsisoft Internet Security") GET pathToSignedReportingExe /value
基本上可以安装两种不同的安全产品,批处理文件需要确定哪一种。由于在安装过程中可能会更改文件夹,因此确定该文件夹的最安全方法似乎是使用上述两个命令。可悲的是,我无法将输出转换为变量以使用它。
这是我当前的测试脚本:
@ECHO OFF
for /f "tokens=2 delims==" %%f in ('WMIC /namespace:\\\\root\\SecurityCenter2 PATH AntiVirusProduct WHERE ^(displayName^="Emsisoft Anti-Malware" or displayName^="Emsisoft Internet Security"^) GET DisplayName /value ^| find "="') do set "EmsiProductName=%%f"
ECHO %EmsiProductName%
for /f "tokens=2 delims==" %%f in ('WMIC /namespace:\\\\root\\SecurityCenter2 PATH AntiVirusProduct WHERE ^(displayName^="Emsisoft Anti-Malware" or displayName^="Emsisoft Internet Security"^) GET pathToSignedReportingExe /value ^| find "="') do set "EmsiProductPath=%%f"
ECHO %EmsiProductPath%
PAUSE
运行时,上面会输出两个错误,即“描述 = RPC 服务器不可用”。我已经尝试转义引号("" 和 \"),而不是转义它们,但输出都是一样的。
我没有想法,所以如果有人有任何建议,我将不胜感激。
【问题讨论】:
-
但是
wmic命令行确实可以自己工作,对吧? -
@aschipfl 是的,他们有。
-
@GT500 试试
WHERE "displayName like 'Emsisoft%%'"。我认为插入符号可能不会在您的命令中产生预期的效果。但是您可以将where子句括在双引号中,并将产品名称括在单引号中。这将使您避免逃避任何事情(即使您继续使用=而不是like)。 -
@rojo 谢谢你,先生,这行得通。 :)
-
不,它们不起作用,因为您正在转义反斜杠 C 样式。这不是必需的。
/namespace:\\root\SecurityCenter2这是没有可用的 RPC 服务器的原因。你似乎有很多问题。
标签: batch-file variables output wmic