How to get "excutable" name in C# of a current process

R

Regis Melo

Hello,

I'm trying to get the "EXE" name of app that runs the current
window. To get the current window I use:

[ DllImport("user32.dll") ]
private static extern
int GetForegroundWindow();


const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);

handle = GetForegroundWindow();
GetWindowText(handle, Buff, nChars)

return Buff.toString(); // Returns the title of
// current window


If this funcion returns "MSN Hotmail", for example, I want to get
"iexplorer.exe", indicating that the current window is "ieplorer.exe".

Thanks,

Regis
 
R

Regis Melo

Hello,

I want to know the name o exe file of current process. Not the name of
my executable....

Tks,

Regis

Ayende said:
Assmebly.GetExecutingAssembly().Name


Hello,

I'm trying to get the "EXE" name of app that runs the current
window. To get the current window I use:

[ DllImport("user32.dll") ]
private static extern
int GetForegroundWindow();


const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);

handle = GetForegroundWindow();
GetWindowText(handle, Buff, nChars)

return Buff.toString(); // Returns the title of
// current window


If this funcion returns "MSN Hotmail", for example, I want to get
"iexplorer.exe", indicating that the current window is "ieplorer.exe".

Thanks,

Regis
 
J

Jon Skeet [C# MVP]

Regis Melo said:
I want to know the name o exe file of current process. Not the name of
my executable....

Have you tried looking through the Modules property of the result of
Process.GetCurrentProcess()?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top