Changeset 6116 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon
- Timestamp:
- 05/03/11 20:16:09 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/Program.cs
r5780 r6116 1 1 using System; 2 2 using System.Diagnostics; 3 using System.Management; 4 using System.Security.Principal; 3 5 using System.Windows.Forms; 4 6 using HeuristicLab.Clients.Hive.SlaveCore.Views; … … 23 25 24 26 /// <summary> 27 /// Gets the owner of a process 28 /// (based on http://www.codeproject.com/KB/cs/processownersid.aspx) 29 /// </summary> 30 public static string GetProcessOwner(int pid) { 31 string ownerSID = String.Empty; 32 string processName = String.Empty; 33 try { 34 ObjectQuery sq = new ObjectQuery 35 ("Select * from Win32_Process Where ProcessID = '" + pid + "'"); 36 ManagementObjectSearcher searcher = new ManagementObjectSearcher(sq); 37 if (searcher.Get().Count == 0) 38 return ownerSID; 39 foreach (ManagementObject oReturn in searcher.Get()) { 40 string[] sid = new String[1]; 41 oReturn.InvokeMethod("GetOwnerSid", (object[])sid); 42 ownerSID = sid[0]; 43 return ownerSID; 44 } 45 } 46 catch { 47 return ownerSID; 48 } 49 return ownerSID; 50 } 51 52 /// <summary> 25 53 /// kill all other slave tray icons, we only want 1 running at a time 26 54 /// (and if a newer version is installed the older one should be killed) 27 55 /// </summary> 28 56 private static void KillOtherInstances() { 57 String currentUserSID = WindowsIdentity.GetCurrent().User.Value; 29 58 Process curProc = Process.GetCurrentProcess(); 30 59 … … 33 62 foreach (Process p in procs) { 34 63 if (p.Id != curProc.Id) { 35 p.Kill(); 64 String procUserSID = GetProcessOwner(p.Id); 65 if (procUserSID == currentUserSID) { 66 p.Kill(); 67 } 36 68 } 37 69 } 38 70 } 39 catch (InvalidOperationException) { 40 } 71 catch (InvalidOperationException) { } 41 72 catch (Exception) { 42 73 MessageBox.Show("There is another instance of the Hive Slave tray icon running which can't be closed.", "HeuristicLab Hive Slave");
Note: See TracChangeset
for help on using the changeset viewer.