文件路径中的wmic空间,导致无实例可用

时间:2012-12-07 06:44:27

标签: wmi wmic

我正在使用wmic来获取有关服务的信息,使用文件的完整路径。

wmic service where PathName="C:\\Windows\\system32\\CxAudMsg64.exe"

哪个工作正常。但是,当我使用带有空格的路径时,如下所示:

wmic service where PathName="C:\\Program Files (x86)\\Common Files\\Adobe\\ARM\\1.0\\armsvc.exe"

它告诉我:“没有可用的实例。”这是不正确的,因为路径是正确的并且服务存在。我是否需要逃离路径中的空间或什么?

2 个答案:

答案 0 :(得分:1)

我的错误。

wmic service

wmic服务显示PathName值有时列出qoutes,有时不列出。你必须检查两者。

wmic service where PathName='"C:\\Program Files (x86)\\Common Files\\Adobe\\ARM\\1.0\\armsvc.exe"'

wmic service where PathName='C:\\Program Files (x86)\\Common Files\\Adobe\\ARM\\1.0\\armsvc.exe'

答案 1 :(得分:0)

TL; DR-

wmic service where "pathname='\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"' AND ServiceSpecificExitCode=0" get name

#OR....

wmic service where (pathname="\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" AND ServiceSpecificExitCode=0) get name

详细信息-

虽然其他答案适用于单准则问题,但对于复合查询却会出错。我建议使用“等于前报价”语法或“ Parwhere Around”语法。这是一些例子

单行+等于后报价

Invalid alias verb          == wmic service where pathname=""C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe"" get name
Invalid query               == wmic service where pathname="\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
Invalid alias verb          == wmic service where pathname="^"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe^"" get name
Invalid alias verb          == wmic service where pathname=^""C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe^"" get name
Invalid query               == wmic service where pathname="\"C:\\ProgramData\\Microsoft\\Windows^ Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
Invalid query               == wmic service where pathname="\"C:\\ProgramData\\Microsoft\\Windows\ Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
Works Perfect               == wmic service where pathname='"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe"' get name

单行+等于前引用

No Instance(s) Available    == wmic service where "pathname='C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe'" get name
No Instance(s) Available    == wmic service where "pathname='^""C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe""'" get name
No Instance(s) Available    == wmic service where "pathname='""C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe""'" get name
Invalid query               == wmic service where "pathname=""C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe""" get name
Invalid alias verb          == wmic service where "pathname='^"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe^"'" get name
Invalid alias verb          == wmic service where "pathname='"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe"'" get name
No Instance(s) Available    == wmic service where "pathname=\"C:\\ProgramData\\Microsoft\\Windows^ Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
No Instance(s) Available    == wmic service where "pathname=\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
Invalid alias verb          == wmic service where "pathname=^"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe^"" get name
Invalid query               == wmic service where "pathname=\"C:\\ProgramData\\Microsoft\\Windows\ Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" get name
Works Perfect               == wmic service where "pathname='\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"'" get name

单处+围在何处

Works Perfect               == wmic service where (pathname="\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"") get name

复合-何处+等号后报价

Invalid alias verb          == wmic service where pathname='"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe"' AND ServiceSpecificExitCode=0 get name
Invalid alias verb          == wmic service where pathname='"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe"' AND ServiceSpecificExitCode='0' get name

复合-等于前加引号

Works Perfect               == wmic service where "pathname='\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"' AND ServiceSpecificExitCode=0" get name

复合-在哪里+围在哪里

Works Perfect               == wmic service where (pathname="\"C:\\ProgramData\\Microsoft\\Windows Defender\\platform\\4.18.1902.2-0\\NisSrv.exe\"" AND ServiceSpecificExitCode=0) get name
相关问题