getwindowmodulefilename (user32)
Last changed: davidsonblake86@gmail.com-72.202.204.193

.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern uint GetWindowModuleFileName(IntPtr hwnd,
   StringBuilder lpszFileName, uint cchFileNameMax);

VB Signature:

  <DllImport("user32.dll", SetLastError := True, CharSet := CharSet.Auto)> _
  Private Shared Function GetWindowModuleFileName(hwnd As IntPtr, _
    lpszFileName As StringBuilder, cchFileNameMax As UInteger) As UInteger
  End Function

User-Defined Types:

None.

Notes:

Since Windows 2000, this function only has access to process internal information and cannot be used globally.

Workaround
Use GetWindowThreadProcessId to get the process ID, then Process.GetProcessById to retrieve the process information. The resultant System.Diagnostics.Process Object's MainModule Property has the Filename Property, which is the Information you are probably searching.

Tips & Tricks:

Please add some!

Sample Code:

StringBuilder fileName = new StringBuilder(2000);

GetWindowModuleFileName(hwnd, fileName, 2000);

Debug.WriteLine(fileName.ToString());

Alternative Managed API:

Do you know one? Please contribute it!

Documentation