Hack Forums
[.NET] VB.NET How to get DirectoryPath of running process? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] VB.NET How to get DirectoryPath of running process? (/showthread.php?tid=5946857)



VB.NET How to get DirectoryPath of running process? - Formula 1 - Mar 3, 2019

How can i get the DirectoryPath of running process? not my application...
Another application that is running...


RE: VB.NET How to get DirectoryPath of running process? - HFDone - Mar 3, 2019

process module property filename https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.modules?view=netframework-4.7.2


RE: VB.NET How to get DirectoryPath of running process? - Vexallus - Mar 3, 2019

Code
Dim x As Process() = Process.GetProcessesByName("TEST")
Dim modulepath As String
modulepath = x(0).MainModule.FileName



RE: VB.NET How to get DirectoryPath of running process? - Formula 1 - Mar 3, 2019

(Mar 3, 2019 11:04 AM)Vexallus Wrote:  
Code
Dim x As Process() = Process.GetProcessesByName("TEST")
Dim modulepath As String
modulepath = x(0).MainModule.FileName

It gives me the path + filename.exe

folder/folder/file.exe

I just need folder/folder


RE: VB.NET How to get DirectoryPath of running process? - Vexallus - Mar 3, 2019

(Mar 3, 2019 11:45 AM)uberhacker Wrote:  It gives me the path + filename.exe

folder/folder/file.exe

I just need folder/folder

you can use .Replace which will output the folder without the file name


RE: VB.NET How to get DirectoryPath of running process? - JiiN - Mar 3, 2019

(Mar 3, 2019 11:45 AM)uberhacker Wrote:  It gives me the path + filename.exe

folder/folder/file.exe

I just need folder/folder

Code
Dim allPath As String = "C:\Windows\explorer.exe"

MsgBox(IO.Path.GetFileName(allPath)) 'Return "explorer.exe"

MsgBox(IO.Path.GetExtension(allPath)) 'Return ".exe"

MsgBox(IO.Path.GetFileNameWithoutExtension(allPath)) 'Return "explorer"

MsgBox(IO.Path.GetDirectoryName(allPath)) 'Return "C:\Windows"

MsgBox(IO.Path.GetFullPath(allPath)) 'Return "C:\Windows\explorer.exe"



RE: VB.NET How to get DirectoryPath of running process? - Formula 1 - Mar 3, 2019

Thank you guys for replying, it works fine