473,598 Members | 3,128 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process.MainMod ule.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.Manageme nt.ManagementSc ope("\\\\localh ost\\root\\cimv 2");
ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT * FROM
Win32_Process") ;
ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms,oq );
ManagementObjec tCollection queryCollection = query.Get();
foreach ( ManagementObjec t mo in queryCollection )
{

but I now need the path of the process executable. ManagementObjec t has a
property "ExecutablePath " but it always seems to be blank, so I use:

PropertyData processIdProper ty = mo.Properties["ProcessId"];
Process process =
Process.GetProc essById(Int32.P arse(processIdP roperty.Value.T oString()));

but now I discover to my horror that, even under XP, the value of
process.MainMod ule.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 2430
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.co m

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:00******** *************** ***********@mic rosoft.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.Manageme nt.ManagementSc ope("\\\\localh ost\\root\\cimv 2");
ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT * FROM
Win32_Process") ;
ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms,oq );
ManagementObjec tCollection queryCollection = query.Get();
foreach ( ManagementObjec t mo in queryCollection )
{

but I now need the path of the process executable. ManagementObjec t has a
property "ExecutablePath " but it always seems to be blank, so I use:

PropertyData processIdProper ty = mo.Properties["ProcessId"];
Process process =
Process.GetProc essById(Int32.P arse(processIdP roperty.Value.T oString()));

but now I discover to my horror that, even under XP, the value of
process.MainMod ule.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.co m

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:00******** *************** ***********@mic rosoft.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.Manageme nt.ManagementSc ope("\\\\localh ost\\root\\cimv 2");
ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT * FROM
Win32_Process") ;
ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms,oq );
ManagementObjec tCollection queryCollection = query.Get();
foreach ( ManagementObjec t mo in queryCollection )
{

but I now need the path of the process executable. ManagementObjec t has a
property "ExecutablePath " but it always seems to be blank, so I use:

PropertyData processIdProper ty = mo.Properties["ProcessId"];
Process process =
Process.GetProc essById(Int32.P arse(processIdP roperty.Value.T oString()));

but now I discover to my horror that, even under XP, the value of
process.MainMod ule.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**@discussio ns.microsoft.co m> wrote in message
news:3E******** *************** ***********@mic rosoft.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.co m

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:00******** *************** ***********@mic rosoft.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.Manageme nt.ManagementSc ope("\\\\localh ost\\root\\cimv 2");
> ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT * FROM
> Win32_Process") ;
> ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms,oq );
> ManagementObjec tCollection queryCollection = query.Get();
> foreach ( ManagementObjec t mo in queryCollection )
> {
>
> but I now need the path of the process executable. ManagementObjec t has
> a
> property "ExecutablePath " but it always seems to be blank, so I use:
>
> PropertyData processIdProper ty = mo.Properties["ProcessId"];
> Process process =
> Process.GetProc essById(Int32.P arse(processIdP roperty.Value.T oString()));
>
> but now I discover to my horror that, even under XP, the value of
> process.MainMod ule.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**@discussio ns.microsoft.co m> wrote in message
news:3E******** *************** ***********@mic rosoft.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.co m

"Dave" <Da**@discussio ns.microsoft.co m> wrote in message
news:00******** *************** ***********@mic rosoft.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.Manageme nt.ManagementSc ope("\\\\localh ost\\root\\cimv 2");
> ObjectQuery oq = new System.Manageme nt.ObjectQuery( "SELECT * FROM
> Win32_Process") ;
> ManagementObjec tSearcher query = new ManagementObjec tSearcher(ms,oq );
> ManagementObjec tCollection queryCollection = query.Get();
> foreach ( ManagementObjec t mo in queryCollection )
> {
>
> but I now need the path of the process executable. ManagementObjec t has
> a
> property "ExecutablePath " but it always seems to be blank, so I use:
>
> PropertyData processIdProper ty = mo.Properties["ProcessId"];
> Process process =
> Process.GetProc essById(Int32.P arse(processIdP roperty.Value.T oString()));
>
> but now I discover to my horror that, even under XP, the value of
> process.MainMod ule.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
1940
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 = Process.GetProcesses(); foreach(Process processid in machineProcesses) { Console.WriteLine("pid: "+processid.Id.ToString()); Console.WriteLine("name: "+processid.MainModule.ModuleName.ToString(); }
7
10804
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. Thanks,
4
317
by: web1110 | last post by:
Given a Process, is there a way to get the full path name of the executable?
9
21615
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 For Each p In Process.GetProcessesByName("EXTRA") If Left(p.MainWindowTitle, 4) = "Appl" Then 'Here I should be able to Bring the Process to the Front!!!
2
1183
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 Process Try processes1 = Process.GetProcesses() For Each p1 In processes1
0
2169
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 exception (Access denied) when I try and check the MainModule.Filename for this. Also, when FireFox fires I also get the same error. Other processes show the MainModule.Filename fine. Does anyone know how I might get around this? Thanks
4
21128
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 following code. sample code:
7
4373
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 System.Diagnostics.Process.GetProcesses(PC.Name) processgrid.Rows.Add(ps.ProcessName, ps.Id) Next ps Any ideas how I can get the process path (using vb 2005)
2
6553
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 (Process currentProcess in processes) 04 { 05 if (null != currentProcess) 06 {
0
7985
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7896
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8389
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3896
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1246
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.