Extended the running instance MessageBox with the paths of the instances. Made to get a better fix for #3526579

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1847 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-05-14 15:44:08 +00:00
parent 6811094a29
commit e5cf074386
5 changed files with 72 additions and 52 deletions

View file

@ -236,51 +236,10 @@ namespace GreenshotPlugin.Core {
// not a valid window handle
return string.Empty;
}
StringBuilder _PathBuffer = new StringBuilder(512);
// Get the process id
uint processid;
IntPtr processid;
User32.GetWindowThreadProcessId(Handle, out processid);
// Try the GetModuleFileName method first since it's the fastest.
// May return ACCESS_DENIED (due to VM_READ flag) if the process is not owned by the current user.
// Will fail if we are compiled as x86 and we're trying to open a 64 bit process...not allowed.
IntPtr hprocess = Kernel32.OpenProcess(ProcessAccessFlags.QueryInformation | ProcessAccessFlags.VMRead, false, processid);
if (hprocess != IntPtr.Zero) {
try {
if (Kernel32.GetModuleFileNameEx(hprocess, IntPtr.Zero, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
return _PathBuffer.ToString();
}
} finally {
Kernel32.CloseHandle(hprocess);
}
}
hprocess = Kernel32.OpenProcess(ProcessAccessFlags.QueryInformation, false, processid);
if (hprocess != IntPtr.Zero) {
try {
// Try this method for Vista or higher operating systems
uint size = (uint)_PathBuffer.Capacity;
if ((Environment.OSVersion.Version.Major >= 6) && (Kernel32.QueryFullProcessImageName(hprocess, 0, _PathBuffer, ref size) && (size > 0))) {
return _PathBuffer.ToString();
}
// Try the GetProcessImageFileName method
if (Kernel32.GetProcessImageFileName(hprocess, _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
string dospath = _PathBuffer.ToString();
foreach (string drive in Environment.GetLogicalDrives()) {
if (Kernel32.QueryDosDevice(drive.TrimEnd('\\'), _PathBuffer, (uint)_PathBuffer.Capacity) > 0) {
if (dospath.StartsWith(_PathBuffer.ToString())) {
return drive + dospath.Remove(0, _PathBuffer.Length);
}
}
}
}
} finally {
Kernel32.CloseHandle(hprocess);
}
}
return string.Empty;
return Kernel32.GetProcessPath(processid);
}
}