How to get full path of running process.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shekoasinger
    New Member
    • May 2010
    • 4

    How to get full path of running process.

    Im working on a Dll Injector. But that is not my problem. I am using a picturebox to display the icon of a running process.
    E.g. If google chrome is running. The picturebox should display the icon of google chrome.

    I can extract the icon to my picturebox only if I know the full path of the process. That API was easily found and works very well.

    But know I want my application to get the full path of a running process automatically as soon as I order it.

    Like in a textbox is write: chrome.exe, and press the button next to it. What do I need to write in the button to get the full path of that running process.(of course only if its running, I if its not running I dont want anything to happned)

    Thanks in Advance.
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    You could use the Modules Property of the process class. Then the FileName would give you the path to the process. Here's an example

    Code:
    Private Sub button2_Click(sender As Object, e As EventArgs)
    	For Each p As Process In Process.GetProcesses()
    		Dim file As String
    		Try
    			file = p.Modules(0).FileName
    		Catch ex As Win32Exception
    			file = "n/a"
    		End Try
    		Console.WriteLine(String.Format("Process {0}: {1}", p.ProcessName, file))
    	Next
    End Sub

    Comment

    Working...