GetModuleFilenameA
API
Imports System.Runtime.InteropServices
Module Module2
' Declare the GetModuleFileNameA function from the kernel32.dll
<DllImport("kernel32.dll", CharSet:=CharSet.Ansi, SetLastError:=True)>
Public Function GetModuleFileNameA(
ByVal hModule As IntPtr,
ByVal lpFilename As System.Text.StringBuilder,
ByVal nSize As UInteger
) As UInteger
End Function
Sub Main()
Dim buffer As New System.Text.StringBuilder(260) ' MAX_PATH
Dim moduleHandle As IntPtr = IntPtr.Zero ' Use IntPtr.Zero for the current process
Dim size As UInteger = CUInt(buffer.Capacity)
' Call the function
Dim result As UInteger = GetModuleFileNameA(moduleHandle, buffer, size)
If result > 0 Then
Console.WriteLine("Module File Name: " & buffer.ToString())
Else
Console.WriteLine("Error retrieving module file name.")
End If
End Sub
End Module
VB.Net
Module Module2
Sub Main()
' Get the path of the currently executing assembly
Dim exePath As String = System.Reflection.Assembly.GetExecutingAssembly().Location
' Display the path
Console.WriteLine("Module File Name: " & exePath)
' Wait for input before closing (optional)
Console.ReadLine()
End Sub
End Module
Module Module2
Sub Main()
' Get a list of all processes
Dim processes() As Process = Process.GetProcesses()
' Loop through each process
For Each process As Process In processes
' Get the main module file path for this process
Dim moduleName As String = process.MainModule.FileName
' Display the path
Console.WriteLine($"Process ID: {process.Id}, Module File Name: {moduleName}")
' Wait for input before closing (optional)
Console.ReadLine()
Next
End Sub
End Module