QueryFullProcessImageName (kernel32)
Last changed: -213.206.248.4

.
Summary
Retrieves the full name of the executable image for the specified process. (by Process Handle)

C# Signature:

[DllImport("kernel32.dll", SetLastError=true)]
static extern bool QueryFullProcessImageName([In]IntPtr hProcess, [In]int dwFlags, [Out]StringBuilder lpExeName, ref int lpdwSize);

VB Signature:

Declare Function QueryFullProcessImageName Lib "kernel32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

System.Diagnostics.Process.MainModule.FileName

Notes:

To query the filename for a process that is running elevated from a process that is not, the .NET api crashes.

This is a workaround.

Tips & Tricks:

Please add some!

Sample Code:

int capacity = 1024;
StringBuilder sb = new StringBuilder(capacity);
IntPtr handle = OpenProcess(ProcessAccess.QueryLimitedInformation, false, process.Id);
QueryFullProcessImageName(handle, 0, sb, ref capacity);
string fullPath = sb.ToString(0, capacity);

Documentation

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684919(v=vs.85).aspx