Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/03/11 20:16:09 (13 years ago)
Author:
ascheibe
Message:

#1233

  • SlaveTrayIcon: don't try to kill TrayIcons from other users
  • split installer to fix config installer bug for users who did not run the installer
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.SlaveTrayIcon/Program.cs

    r5780 r6116  
    11using System;
    22using System.Diagnostics;
     3using System.Management;
     4using System.Security.Principal;
    35using System.Windows.Forms;
    46using HeuristicLab.Clients.Hive.SlaveCore.Views;
     
    2325
    2426    /// <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>
    2553    /// kill all other slave tray icons, we only want 1 running at a time
    2654    /// (and if a newer version is installed the older one should be killed)
    2755    /// </summary>
    2856    private static void KillOtherInstances() {
     57      String currentUserSID = WindowsIdentity.GetCurrent().User.Value;
    2958      Process curProc = Process.GetCurrentProcess();
    3059
     
    3362        foreach (Process p in procs) {
    3463          if (p.Id != curProc.Id) {
    35             p.Kill();
     64            String procUserSID = GetProcessOwner(p.Id);
     65            if (procUserSID == currentUserSID) {
     66              p.Kill();
     67            }
    3668          }
    3769        }
    3870      }
    39       catch (InvalidOperationException) {
    40       }
     71      catch (InvalidOperationException) { }
    4172      catch (Exception) {
    4273        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.