954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get the path of a running process?

Hi all...

How to get the full path of a file which is currently running?? suppose from cmd or directly someone starts an application or any kind of file( text file, word file, mp3 etc) my C# application need to get the path of the opened file... For eg: if someone opens c:\dir\a.txt , then my C# program need to get that path directly...??? How to do that???

Plz help me ....

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

Application.ExecutablePath - Get the path of executable file that started the application.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

See.. i dnt need the path of my C# application.... i need the full path of the other running processess... suppose if i opened a text file or a word file then since my C# application is working in background , this pgm must get the path of the opened text file...

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 
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
Banned
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
 

Upgrade to Vista then :)

serkan sendur
Postaholic
Banned
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
Banned
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

zydaru
Newbie Poster
11 posts since Aug 2009
Reputation Points: 10
Solved Threads: 0
 
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
 

sorry, im not getting dat... still im getting only the path of the notepad.exe ie c:\windows\systm32 not the path of the opened notepad..!!!!!

getkiran1
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 0
 

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
 
See.. i dnt need the path of my C# application.... i need the full path of the other running processess... suppose if i opened a text file or a word file then since my C# application is working in background , this pgm must get the path of the opened text file...

It occurred to me, because this thread has not been marked SOLVED, you might be trying to figure out what process has a file open: investigating who has my file locked

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

[code]
@sknake
You said very weel:

If you open a text file with notepad then this happens:

* Notepad.exe opens
* notepad opens your text file

I want to find out what is the path of the TextFile opened with the NotePad. Is this posible?
[icode]

Ionesta
Newbie Poster
1 post since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: