471,327 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 software developers and data experts.

Process.MainModule.Filename is in DOS format

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(processIdProper ty.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?
--
Dave
Dec 29 '05 #1
4 2294
Dave,

You can call the GetLongPathName API function through the P/Invoke layer
to get the long filename given it's short name.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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(processIdProper ty.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?
--
Dave

Jan 1 '06 #2
Thanks Nicholas, that's just what I needed. It all seemed so much easier
before Manged Code!

Do you know of a resource anywhere that can be used as a "reverse lookup"
for API calls - ie. "is there an API call that does this?"?
--
Dave
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dave,

You can call the GetLongPathName API function through the P/Invoke layer
to get the long filename given it's short name.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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(processIdProper ty.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?
--
Dave


Jan 4 '06 #3
I use
http://msdn.microsoft.com/netframewo...l/win32map.asp
for my "reverse lookups"

--
Colin Neller
http://www.colinneller.com/blog
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Thanks Nicholas, that's just what I needed. It all seemed so much easier
before Manged Code!

Do you know of a resource anywhere that can be used as a "reverse lookup"
for API calls - ie. "is there an API call that does this?"?
--
Dave
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dave,

You can call the GetLongPathName API function through the P/Invoke
layer
to get the long filename given it's short name.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
>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(processIdProper ty.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?
> --
> Dave


Jan 4 '06 #4
That looks excellent. Many thanks.
--
Dave
"Colin Neller" wrote:
I use
http://msdn.microsoft.com/netframewo...l/win32map.asp
for my "reverse lookups"

--
Colin Neller
http://www.colinneller.com/blog
"Dave" <Da**@discussions.microsoft.com> wrote in message
news:3E**********************************@microsof t.com...
Thanks Nicholas, that's just what I needed. It all seemed so much easier
before Manged Code!

Do you know of a resource anywhere that can be used as a "reverse lookup"
for API calls - ie. "is there an API call that does this?"?
--
Dave
"Nicholas Paldino [.NET/C# MVP]" wrote:
Dave,

You can call the GetLongPathName API function through the P/Invoke
layer
to get the long filename given it's short name.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
>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(processIdProper ty.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?
> --
> Dave


Jan 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Greg Merideth | last post: by
7 posts views Thread by Christopher Attard | last post: by
4 posts views Thread by web1110 | last post: by
2 posts views Thread by alvis | last post: by
4 posts views Thread by Nayan | last post: by
7 posts views Thread by xla76 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.