mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 13:10:00 -07:00
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:
parent
6811094a29
commit
e5cf074386
5 changed files with 72 additions and 52 deletions
|
@ -215,7 +215,23 @@ namespace Greenshot {
|
||||||
if (filesToOpen.Count > 0) {
|
if (filesToOpen.Count > 0) {
|
||||||
SendData(transport);
|
SendData(transport);
|
||||||
} else {
|
} else {
|
||||||
MessageBox.Show(Language.GetString(LangKey.error_multipleinstances), Language.GetString(LangKey.error));
|
StringBuilder instanceInfo = new StringBuilder();
|
||||||
|
bool matchedThisProcess = false;
|
||||||
|
int index = 1;
|
||||||
|
foreach (Process greenshotProcess in Process.GetProcessesByName("greenshot")) {
|
||||||
|
try {
|
||||||
|
instanceInfo.Append(index++ + ": ").AppendLine(Kernel32.GetProcessPath(new IntPtr(greenshotProcess.Id)));
|
||||||
|
if (Process.GetCurrentProcess().Id == greenshotProcess.Id) {
|
||||||
|
matchedThisProcess = true;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LOG.Debug(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!matchedThisProcess) {
|
||||||
|
instanceInfo.Append(index++ + ": ").AppendLine(Kernel32.GetProcessPath(new IntPtr(Process.GetCurrentProcess().Id)));
|
||||||
|
}
|
||||||
|
MessageBox.Show(Language.GetString(LangKey.error_multipleinstances) + "\r\n" + instanceInfo.ToString(), Language.GetString(LangKey.error));
|
||||||
}
|
}
|
||||||
FreeMutex();
|
FreeMutex();
|
||||||
Application.Exit();
|
Application.Exit();
|
||||||
|
|
|
@ -92,10 +92,10 @@ EndSelection:<<<<<<<4
|
||||||
try {
|
try {
|
||||||
IntPtr hWnd = User32.GetClipboardOwner();
|
IntPtr hWnd = User32.GetClipboardOwner();
|
||||||
if (hWnd != IntPtr.Zero) {
|
if (hWnd != IntPtr.Zero) {
|
||||||
uint pid = 0;
|
IntPtr pid = IntPtr.Zero;
|
||||||
uint tid = User32.GetWindowThreadProcessId( hWnd, out pid );
|
IntPtr tid = User32.GetWindowThreadProcessId( hWnd, out pid);
|
||||||
Process me = Process.GetCurrentProcess();
|
Process me = Process.GetCurrentProcess();
|
||||||
Process ownerProcess = Process.GetProcessById( (int)pid );
|
Process ownerProcess = Process.GetProcessById( pid.ToInt32() );
|
||||||
// Exclude myself
|
// Exclude myself
|
||||||
if (ownerProcess != null && me.Id != ownerProcess.Id) {
|
if (ownerProcess != null && me.Id != ownerProcess.Id) {
|
||||||
// Get Process Name
|
// Get Process Name
|
||||||
|
|
|
@ -236,51 +236,10 @@ namespace GreenshotPlugin.Core {
|
||||||
// not a valid window handle
|
// not a valid window handle
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
StringBuilder _PathBuffer = new StringBuilder(512);
|
|
||||||
// Get the process id
|
// Get the process id
|
||||||
uint processid;
|
IntPtr processid;
|
||||||
User32.GetWindowThreadProcessId(Handle, out processid);
|
User32.GetWindowThreadProcessId(Handle, out processid);
|
||||||
|
return Kernel32.GetProcessPath(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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
[DllImport("kernel32", SetLastError = true)]
|
[DllImport("kernel32", SetLastError = true)]
|
||||||
public static extern int ResumeThread(IntPtr hThread);
|
public static extern int ResumeThread(IntPtr hThread);
|
||||||
[DllImport("kernel32", SetLastError = true)]
|
[DllImport("kernel32", SetLastError = true)]
|
||||||
public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, bool bInheritHandle, uint dwProcessId);
|
public static extern IntPtr OpenProcess(ProcessAccessFlags dwDesiredAccess, bool bInheritHandle, IntPtr dwProcessId);
|
||||||
[DllImport("kernel32", SetLastError = true)]
|
[DllImport("kernel32", SetLastError = true)]
|
||||||
public static extern bool QueryFullProcessImageName(IntPtr hProcess, uint dwFlags, StringBuilder lpExeName, ref uint lpdwSize);
|
public static extern bool QueryFullProcessImageName(IntPtr hProcess, uint dwFlags, StringBuilder lpExeName, ref uint lpdwSize);
|
||||||
[DllImport("kernel32", SetLastError = true)]
|
[DllImport("kernel32", SetLastError = true)]
|
||||||
|
@ -72,5 +72,53 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
[DllImport("psapi", SetLastError = true)]
|
[DllImport("psapi", SetLastError = true)]
|
||||||
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
|
public static extern uint GetProcessImageFileName(IntPtr hProcess, StringBuilder lpImageFileName, uint nSize);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Method to get the process path
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="processid"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string GetProcessPath(IntPtr processid) {
|
||||||
|
StringBuilder _PathBuffer = new StringBuilder(512);
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,9 +396,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
|
[DllImport("user32", SetLastError = true, CharSet = CharSet.Auto)]
|
||||||
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
|
public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
|
||||||
|
|
||||||
[DllImport("user32", SetLastError = true)]
|
|
||||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
|
||||||
|
|
||||||
/// uiFlags: 0 - Count of GDI objects
|
/// uiFlags: 0 - Count of GDI objects
|
||||||
/// uiFlags: 1 - Count of USER objects
|
/// uiFlags: 1 - Count of USER objects
|
||||||
/// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers)
|
/// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue