0
我想查找系统进程的可执行路径,我遵循WMI方法,我使用Process.EnterDebugMode()为我的进程获取访问OS进程属性的特权,但仍然在调用ManagementObject.GetPropertyValue(“ExecutablePath” )返回null,我试图为smss.exe进程。如何访问C#中的系统进程属性?
下面是代码:
static void Main(string[] args)
{
int processID = 536; // Just trying with the PID of smss.exe running in my system
System.Diagnostics.Process.EnterDebugMode();
ConnectionOptions options = new ConnectionOptions();
options.EnablePrivileges = true;
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope(@"\\.\root\cimv2", options);
string NameProperty = "Name";
string PidProperty = "ProcessId";
string FullPathProperty = "ExecutablePath";
string query;
query = string.Format("select {0}, {1}, {2} from Win32_Process where {1} = {3}", NameProperty, PidProperty, FullPathProperty, processID);
ObjectQuery objectQuery = new ObjectQuery(query);
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, objectQuery);
foreach (ManagementObject processEntry in searcher.Get())
{
if (processEntry.GetPropertyValue(PidProperty) != null)
{
int value = Convert.ToInt32(processEntry.GetPropertyValue(PidProperty));
if (value == processID)
{
if (processEntry.GetPropertyValue(FullPathProperty) != null)
{
System.Windows.Forms.MessageBox.Show(processEntry[FullPathProperty].ToString());
}
}
}
}
}
除了WMI以外,还有其他的方法可以帮助性能计数器功能吗? –