G
Guest
I am writing a C# app in which I need to enumerate the processes running on
the PC. I have succesfully done this as follows (assuming the app is running
on NT4, XP, 2000 or 2003):
ManagementScope ms = new
System.Management.ManagementScope("\\\\localhost\\root\\cimv2");
ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM
Win32_Process");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryCollection = query.Get();
foreach ( ManagementObject mo in queryCollection)
{
but I now need the path of the process executable. ManagementObject has a
property "ExecutablePath" but it always seems to be blank, so I use:
PropertyData processIdProperty = mo.Properties["ProcessId"];
Process process =
Process.GetProcessById(Int32.Parse(processIdProperty.Value.ToString()));
but now I discover to my horror that, even under XP, the value of
process.MainModule.FileName is a DOS-format short filename with tildes, which
is not what I want.
Can anyone tell me how to get the executable path of the process in
long-filename format?
the PC. I have succesfully done this as follows (assuming the app is running
on NT4, XP, 2000 or 2003):
ManagementScope ms = new
System.Management.ManagementScope("\\\\localhost\\root\\cimv2");
ObjectQuery oq = new System.Management.ObjectQuery("SELECT * FROM
Win32_Process");
ManagementObjectSearcher query = new ManagementObjectSearcher(ms,oq);
ManagementObjectCollection queryCollection = query.Get();
foreach ( ManagementObject mo in queryCollection)
{
but I now need the path of the process executable. ManagementObject has a
property "ExecutablePath" but it always seems to be blank, so I use:
PropertyData processIdProperty = mo.Properties["ProcessId"];
Process process =
Process.GetProcessById(Int32.Parse(processIdProperty.Value.ToString()));
but now I discover to my horror that, even under XP, the value of
process.MainModule.FileName is a DOS-format short filename with tildes, which
is not what I want.
Can anyone tell me how to get the executable path of the process in
long-filename format?