gpt4 book ai didi

c# - WMI 查询中的转义字符问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:07 25 4
gpt4 key购买 nike

processName.Name = @"\\dfs\ns1\Application_Data\tiny\Development\tinyLOS\tinyLOS.exe";

string wmiQuery = string.Format("select CommandLine from Win32_Process where PathName='{0}'", processName.Name);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(wmiQuery);
ManagementObjectCollection retObjectCollection = searcher.Get();

我正在尝试使用 WMI 在 C# 中运行上述代码,但在执行时我一直收到无效查询错误。我怀疑转义反斜杠是个问题,但我想我已经用 @ 解决了这个问题。我是否遗漏了一些简单的东西,因为这看起来应该可以正常执行?

(注意:反斜杠去掉后执行查询)

最佳答案

您需要传递转义的斜杠,它是 ExecutablePath 而不是 PathName

wmiQuery = @"SELECT CommandLine FROM Win32_Process WHERE ExecutablePath =
'C:\\Program Files\\Microsoft Security Client\\msseces.exe'";

var searcher = new ManagementObjectSearcher("root\\CIMV2", wmiQuery);

foreach (ManagementObject queryObj in searcher.Get())
Console.WriteLine("CommandLine: {0}", queryObj["CommandLine"]);

为了

CommandLine: "C:\Program Files\Microsoft Security Client\msseces.exe" -hide -runkey

关于c# - WMI 查询中的转义字符问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31568343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com