Application.ExecutablePath - Get the path of executable file that started the application.
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
private void button2_Click(object sender, EventArgs e)
{
foreach (Process p in Process.GetProcesses())
{
string procFile;
try
{
procFile = p.Modules[0].FileName;
}
catch (Win32Exception)
{
procFile = "n/a";
}
Console.WriteLine(string.Format("Process {0}: {1}", p.ProcessName, procFile));
}
}
If you open a text file with notepad then this happens: Notepad.exe opens
notepad opens your text file
notepad reads the text file in to memory
notepad closes the text file
notepad sits there waiting for user interaction
You can use the win32 API to see what files a process has open, but it won't give you the information you want in every case.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
open task manager, you dont need c# to see process execution paths.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
serkan -- I think windows only started showing execution paths in Vista and later operating systems. AFAIK you can't see that information in XP with the task manager.
I use SIW for all process inspection tasks and various other windows issues. You can tell what proc has what files open, what libraries, what proc is listening on what port, see named pipes, and many other things.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
No thanks :P I'll wait on windows 7 to mature!
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
there is a microsoft event in miami on 24th of september, they are giving away free windows 7 license to attendees. the registration is free from microsoft website. i was going to go with coworkers but i am too lazy to install it to my laptop. i want to stay with vista for another year unfortunately.
it is 4:30 am dude, you gotta sleep.
serkan sendur
Postaholic
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
My day begins at 2am, Its time to work! I work 7 days a week :(. I have classes during the day on most days so I get in early and get most of my work done before people get in the office and it gets crazy.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Hello, in addition to what this thread was about I was wondering if it's possible for a C# application to know what application is active. Suppose I have opened a .doc, .xls, .mdb, .ppt and I move from to another by Alt+Tab or click on the taskbar. Can I know to which one I moved to, when I moved to it?
Thanks
You should create your own thread to ask questions, not append them to someone elses'.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
Listen if you open notepad.exe, then you open "File.txt" it opens the file -- reads it in to memory -- and closes it. The file does not remain open thus you cannot find it. What are you really trying to do here?
Some applications like Word will hold a lock on the file I believe.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735