Visual C# Developer Center >
Visual C# Forums
>
Visual C# General
>
Can we get the Application name from Task manager's Image Name or from process name in C#?
Can we get the Application name from Task manager's Image Name or from process name in C#?
- We can view any application (.exe) image name on Task Manager as for example:
firefox = firefox.exe
Microsoft Office Word = WINWORD.exe
So my question is; is it possible tio retreive the application name (Firefox, Microsoft Office Word etc) by just having the process name (WINWORD.EXE)?
Obv this is achievable by hard coding it but i want it in a general case (for most applications whose name that cant be easily determined by just looking at their process name (.exe)).....
cheers
Answers
- Task manager is showing you the Process.MainWindowTitle text. This can actually change during runtime of a program, so there's no way to get it from nothing but a filename, but you can get it from any running processing using the System.Diagnostics.Process class.
Reed Copsey, Jr. - http://reedcopsey.com- Proposed As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
- Unproposed As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
- Marked As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
All Replies
- I'm not sure if it would work but you could try using reflection to try and get the product name of the assembly that is running. I really don't know if that would work for none .NET applications though.
- Task manager is showing you the Process.MainWindowTitle text. This can actually change during runtime of a program, so there's no way to get it from nothing but a filename, but you can get it from any running processing using the System.Diagnostics.Process class.
Reed Copsey, Jr. - http://reedcopsey.com- Proposed As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
- Unproposed As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
- Marked As Answer byRudedog2ModeratorTuesday, November 03, 2009 5:49 PM
- is your question related to this?
richTextBox1.Text = System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); richTextBox2.Text = System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Balaji Baskar - I believe you'll want:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx
http://msdn.microsoft.com/en-us/library/system.diagnostics.processmodule.aspx
Specifically "Process.GetAllProcesses()" and maybe a few things from the ProcessModule class. Either way you'll want the System.Diagnostics namespace and, as previously mentioned, maybe reflection.- Proposed As Answer byLuke_UK Wednesday, November 04, 2009 1:29 PM
- Unproposed As Answer byprogramatic Saturday, November 07, 2009 3:52 PM
- Seems impossible unless you hard wire from the filename.


