/// <summary> /// Obtain the information about the KWM instance that is related to /// our instance, if any. /// </summary> public void FindOtherProcess() { State = WmOtherProcessState.None; OtherProcess = null; OtherWindowHandle = IntPtr.Zero; Process currentProcess = Process.GetCurrentProcess(); String procName = currentProcess.ProcessName; WindowsIdentity userWI = WindowsIdentity.GetCurrent(); // Try to find a matching process. foreach (Process p in Process.GetProcessesByName(procName)) { String stringSID = KSyscalls.GetProcessSid(p); // Ignore our current process. if (p.Id == currentProcess.Id) { continue; } bool InOurSessionFlag = currentProcess.SessionId == p.SessionId; // This process has been started by the current user. if (String.Compare(stringSID, userWI.User.Value, true) == 0) { if (InOurSessionFlag) { State = WmOtherProcessState.OurInCurrentSession; } else { State = WmOtherProcessState.OurInOtherSession; } OtherProcess = p; break; } if (InOurSessionFlag) { State = WmOtherProcessState.NotOurInCurrentSession; OtherProcess = p; break; } } // Process found. Get the main window handle. if (OtherProcess != null) { OtherWindowHandle = Program.GetOtherKwmHandle(); } }
/// <summary> /// Obtain the information about the KWM instance that is related to /// our instance, if any. /// </summary> public void FindOtherProcess() { State = WmOtherProcessState.None; OtherProcess = null; OtherWindowHandle = IntPtr.Zero; Process currentProcess = Process.GetCurrentProcess(); String procName = currentProcess.ProcessName; WindowsIdentity userWI = WindowsIdentity.GetCurrent(); // Try to find a matching process. foreach (Process p in Process.GetProcessesByName(procName)) { String stringSID = KSyscalls.GetProcessSid(p); // Ignore our current process. if (p.Id == currentProcess.Id) continue; bool InOurSessionFlag = currentProcess.SessionId == p.SessionId; // This process has been started by the current user. if (String.Compare(stringSID, userWI.User.Value, true) == 0) { if (InOurSessionFlag) State = WmOtherProcessState.OurInCurrentSession; else State = WmOtherProcessState.OurInOtherSession; OtherProcess = p; break; } if (InOurSessionFlag) { State = WmOtherProcessState.NotOurInCurrentSession; OtherProcess = p; break; } } // Process found. Get the main window handle. if (OtherProcess != null) OtherWindowHandle = Program.GetOtherKwmHandle(); }