Getting processes complete path correctly

  • Thread starter Thread starter SQACSharp
  • Start date Start date
S

SQACSharp

Hi,

I'm trying to get the complete path of all .exe returned by
Process.GetProcesses()

The problem is the "theprocess.MainModule.FileName"...sometime for
some process it return stange invalid path like this : \??\c:
\blablabla\myexe.exe

Is there any other way to get the correct path (without the \??\)

Here is the code :
//...
using System.Diagnostics;
//...
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{

MessageBox.Show(theprocess.MainModule.FileName);

}

Thanks!
 
Hi,

The prefix on the path that you are probably talking about is \\?\ and it is
a perfectly valid prefix for a path.

Check out the following link on MSDN for more information. Specifically,
pay attention to the section titled "Maximum Path Length".

http://msdn2.microsoft.com/en-us/library/aa365247.aspx

Hope this helps,

-Trey

--
-----------------------------
Trey Nash
Author of "Accelerated C# 2008" and "Accelerated C# 2005"
Apress




I'm trying to get the complete path of all .exe returned by
Process.GetProcesses()
The problem is the "theprocess.MainModule.FileName"...sometime for
some process it return stange invalid path like this : \??\c:
\blablabla\myexe.exe
Is there any other way to get the correct path (without the \??\)
Here is the code :
//...
using System.Diagnostics;
//...
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
MessageBox.Show(theprocess.MainModule.FileName);

Thanks!- Hide quoted text -

- Show quoted text -


Maybe this path is "valid" but it's not valid when trying to retrieve
the associated icon from the .exe like this :

//...
SHFILEINFO shinfo = new SHFILEINFO();
hImgSmall = SHGetFileInfo(theprocess.MainModule.FileName, 0, ref
shinfo,(uint)Marshal.SizeOf(shinfo), SHGFI_ICON |SHGFI_SMALLICON);
//...

How can i convert this path to a "normal" valid path usable for other
function like SHGetFileInfo function ???
Any other way to get the path without the \\??\ prefix ??

Thanks!
 
The prefix on thepaththat you are probably talking about is \\?\ and it is
a perfectly valid prefix for apath.
Check out the following link on MSDN for more information. Specifically,
pay attention to the section titled "MaximumPathLength".

Hope this helps,

--
news:24c9a19e-00cd-4097-b143-1eb8f84baa80@i37g2000hsd.googlegroups.com...
Hi,
I'm trying to get thecompletepathof all .exe returned by
Process.GetProcesses()
The problem is the "theprocess.MainModule.FileName"...sometime for
some process it return stange invalidpathlike this : \??\c:
\blablabla\myexe.exe
Is there any other way to get the correctpath(without the \??\)
Here is the code :
//...
using System.Diagnostics;
//...
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
MessageBox.Show(theprocess.MainModule.FileName);
}
Thanks!- Hide quoted text -
- Show quoted text -

Maybe thispathis "valid" but it's not valid when trying to retrieve
the associated icon from the .exe like this :

//...
SHFILEINFO shinfo = new SHFILEINFO();
hImgSmall = SHGetFileInfo(theprocess.MainModule.FileName, 0, ref
shinfo,(uint)Marshal.SizeOf(shinfo), SHGFI_ICON |SHGFI_SMALLICON);
//...

How can i convert thispathto a "normal" validpathusable for other
function like SHGetFileInfo function ???
Any other way to get thepathwithout the \\??\ prefix ??

Thanks!- Hide quoted text -

- Show quoted text -

Finally found a solution :
Remove the first 4 characters to remove the \??\
GetLongPathName api

Not sure if it's the best solution, but look like a lot of process
viewer tool use this kind of ugly direct manipulation with the path.
 
Back
Top