Ejemplo n.º 1
0
 public static Exception KillProcess(string processName, bool isCoreProcess)
 {
     return(ServiceOperations.RunOperation(delegate(object param0, EventArgs param1)
     {
         Process[] processesByName = Process.GetProcessesByName(processName);
         if (processesByName != null)
         {
             foreach (Process process in processesByName)
             {
                 using (process)
                 {
                     if (!isCoreProcess || ServiceOperations.IsWindowsCoreProcess(process))
                     {
                         ServiceOperations.Tracer.TraceDebug <string>(0L, "Killing process: {0}", process.MainModule.FileName);
                         process.Kill();
                     }
                     else
                     {
                         ServiceOperations.Tracer.TraceDebug <string>(0L, "Skipped killing {0} since it does not appear to be a windows core process", process.MainModule.FileName);
                     }
                 }
             }
         }
     }));
 }
Ejemplo n.º 2
0
        public static Exception KillService(string serviceName, string reason)
        {
            ServiceOperations.Tracer.TraceDebug <string>(0L, "KillService({0}) called", serviceName);
            Exception innerEx = null;
            Exception ex      = null;

            try
            {
                ex = ServiceOperations.RunOperation(delegate(object param0, EventArgs param1)
                {
                    using (Process serviceProcess = ServiceOperations.GetServiceProcess(serviceName, out innerEx))
                    {
                        if (serviceProcess != null)
                        {
                            serviceProcess.Kill();
                            ServiceOperations.Tracer.TraceDebug <string>(0L, "Killed({0})", serviceName);
                        }
                    }
                });
                if (ex == null)
                {
                    ex = innerEx;
                }
                if (ex != null)
                {
                    ServiceOperations.Tracer.TraceError <string, Exception>(0L, "KillService({0}) fails: {1}", serviceName, ex);
                }
            }
            finally
            {
                ReplayCrimsonEvents.ServiceKilled.Log <string, string, string>(serviceName, reason, (ex != null) ? ex.Message : "<None>");
            }
            return(ex);
        }
Ejemplo n.º 3
0
        public static bool IsServiceRunningOnNode(string serviceName, string nodeName, out Exception ex)
        {
            ex = null;
            bool fRunning = false;

            ex = ServiceOperations.RunOperation(delegate(object param0, EventArgs param1)
            {
                ServiceController serviceController = new ServiceController(serviceName, nodeName);
                using (serviceController)
                {
                    ServiceOperations.Tracer.TraceDebug <string, ServiceControllerStatus, string>(0L, "IsServiceRunningOnNode: {0} is {1} on {2}.", serviceName, serviceController.Status, nodeName);
                    if (serviceController.Status == ServiceControllerStatus.Running)
                    {
                        fRunning = true;
                    }
                }
            });
            if (ex != null)
            {
                ServiceOperations.Tracer.TraceError <string, string, Exception>(0L, "IsServiceRunningOnNode( {0}, {1} ): Caught exception {2}", serviceName, nodeName, ex);
            }
            return(fRunning);
        }