473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2412
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Greg Merideth | last post by:
This piece of code creates a fault at the attempt to get the modulename of the process when (in server2k or xp) the code gets to the "System" prcoess. Process machineProcesses =...
7
by: Christopher Attard | last post by:
Hi, How can I obtain the full path for a running process without using WMI? I've tried to use the Process.StartInfo.WorkingDirectory but it's not valid since the process is already running. ...
4
by: web1110 | last post by:
Given a Process, is there a way to get the full path name of the executable?
9
by: DraguVaso | last post by:
Hi, I want my application to bring another application to the Front. I thought best way to do this was by the Process-model: Dim c As Process = Process.GetCurrentProcess() Dim p As Process...
2
by: alvis | last post by:
hi i have a windows service that uses an excell workbook when i create the excell app i cant distroy it after i am finished i am using this code whats wrong? thanks Dim processes1(), p1 As...
0
by: Randy | last post by:
Hello, I'm trying to trap different process using a little c# app I wrote. I'm having a problem reading the MainModule.Filename on certain processes...such as when I fire up cmd.exe, I get an...
4
by: Nayan | last post by:
The base process owns this thread. But the visible window is owned by the thread. How do I get the owner Process ID from a Thread ID? To understand, look at this "<<--" pointer in the...
7
by: xla76 | last post by:
Using WMI I can get the full path of a process on a remote computer: "SELECT ExecutablePath FROM Win32_Process" Without wmi I can get theprocessname and id: For Each ps In...
2
by: Tim | last post by:
Hey guys, I tried to get a process handle with the following code snippet: 00 Process processes = Process.GetProcesses(); 01 if (null != processes && processes.Length 0) 02 { 03 foreach...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.