c# - Trouble with escape character in WMI query -
processname.name = @"\\dfs\ns1\application_data\tiny\development\tinylos\tinylos.exe"; string wmiquery = string.format("select commandline win32_process pathname='{0}'", processname.name); managementobjectsearcher searcher = new managementobjectsearcher(wmiquery); managementobjectcollection retobjectcollection = searcher.get();
i trying run above code in c# using wmi keep getting invalid query error when executes. suspect it's problem escaping slash thought had accounted @. missing simple because looks should execute ok?
(note: query executes when slashes removed)
you need pass escaped slashes , it's executablepath
not pathname
wmiquery = @"select commandline win32_process 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"]);
for
commandline: "c:\program files\microsoft security client\msseces.exe" -hide -runkey
Comments
Post a Comment