private static int ProcessComparison(Process x, Process y)
        {
            int num = string.Compare(ProcessBaseCommand.SafeGetProcessName(x), ProcessBaseCommand.SafeGetProcessName(y), StringComparison.CurrentCultureIgnoreCase);

            if (num == 0)
            {
                return(ProcessBaseCommand.SafeGetProcessId(x) - ProcessBaseCommand.SafeGetProcessId(y));
            }
            else
            {
                return(num);
            }
        }
 protected override void ProcessRecord()
 {
     foreach (Process process in base.MatchingProcesses())
     {
         if (!base.ShouldProcess(StringUtil.Format(ProcessResources.ProcessNameForConfirmation, ProcessBaseCommand.SafeGetProcessName(process), ProcessBaseCommand.SafeGetProcessId(process))))
         {
             continue;
         }
         if (process.Id != 0)
         {
             string str = string.Concat("Select * From Win32_Process Where ProcessId=", ProcessBaseCommand.SafeGetProcessId(process));
             ManagementObjectSearcher   managementObjectSearcher    = new ManagementObjectSearcher(str);
             ManagementObjectCollection managementObjectCollections = managementObjectSearcher.Get();
             foreach (ManagementObject managementObject in managementObjectCollections)
             {
                 try
                 {
                     managementObject.InvokeMethod("AttachDebugger", null);
                 }
                 catch (ManagementException managementException1)
                 {
                     ManagementException managementException = managementException1;
                     string message = managementException.Message;
                     if (!string.IsNullOrEmpty(message))
                     {
                         message = message.Trim();
                     }
                     ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(StringUtil.Format(ProcessResources.DebuggerError, message, null)), "GetWMIManagementException", ErrorCategory.InvalidOperation, null);
                     base.WriteError(errorRecord);
                 }
             }
         }
         else
         {
             base.WriteNonTerminatingError(process, null, ProcessResources.NoDebuggerFound, "NoDebuggerFound", ErrorCategory.ObjectNotFound);
         }
     }
 }
        private void AddIdempotent(Process process)
        {
            int hashCode = ProcessBaseCommand.SafeGetProcessName(process).GetHashCode() ^ ProcessBaseCommand.SafeGetProcessId(process);

            if (!this._keys.ContainsKey(hashCode))
            {
                this._keys.Add(hashCode, process);
                this._matchingProcesses.Add(process);
            }
        }
 internal void WriteNonTerminatingError(Process process, Exception innerException, string resourceId, string errorId, ErrorCategory category)
 {
     this.WriteNonTerminatingError(ProcessBaseCommand.SafeGetProcessName(process), ProcessBaseCommand.SafeGetProcessId(process), process, innerException, resourceId, errorId, category);
 }
 protected override void ProcessRecord()
 {
     if (this.myMode == ProcessBaseCommand.MatchMode.All || this.myMode == ProcessBaseCommand.MatchMode.ByName && this.processNames == null)
     {
         throw PSTraceSource.NewInvalidOperationException();
     }
     else
     {
         foreach (Process process in base.MatchingProcesses())
         {
             if (!base.ShouldProcess(StringUtil.Format(ProcessResources.ProcessNameForConfirmation, ProcessBaseCommand.SafeGetProcessName(process), ProcessBaseCommand.SafeGetProcessId(process))))
             {
                 continue;
             }
             try
             {
                 bool hasExited = process.HasExited;
                 if (!hasExited)
                 {
                     if (Process.GetCurrentProcess().Id != ProcessBaseCommand.SafeGetProcessId(process))
                     {
                         if (!this.Force)
                         {
                             string processOwnerId = this.GetProcessOwnerId(process);
                             if (processOwnerId.Contains("\\"))
                             {
                                 processOwnerId = processOwnerId.Substring(processOwnerId.LastIndexOf("\\", StringComparison.CurrentCultureIgnoreCase) + 1);
                             }
                             if (!string.Equals(processOwnerId, Environment.UserName, StringComparison.CurrentCultureIgnoreCase))
                             {
                                 string str = StringUtil.Format(ProcessResources.ConfirmStopProcess, ProcessBaseCommand.SafeGetProcessName(process), ProcessBaseCommand.SafeGetProcessId(process));
                                 if (!base.ShouldContinue(str, null, ref this.yesToAll, ref this.noToAll))
                                 {
                                     continue;
                                 }
                             }
                         }
                         if (string.Equals(ProcessBaseCommand.SafeGetProcessName(process), "SVCHOST", StringComparison.CurrentCultureIgnoreCase))
                         {
                             string str1 = string.Concat("Select * From Win32_Service Where ProcessId=", ProcessBaseCommand.SafeGetProcessId(process), " And State !='Stopped' ");
                             ManagementObjectCollection wmiQueryResults = this.GetWmiQueryResults(str1);
                             if (wmiQueryResults != null)
                             {
                                 foreach (ManagementObject wmiQueryResult in wmiQueryResults)
                                 {
                                     using (ServiceController serviceController = new ServiceController(wmiQueryResult["Name"].ToString()))
                                     {
                                         try
                                         {
                                             serviceController.Stop();
                                             serviceController.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan((long)0x1312d00));
                                         }
                                         catch (Win32Exception win32Exception)
                                         {
                                             continue;
                                         }
                                         catch (InvalidOperationException invalidOperationException)
                                         {
                                             continue;
                                         }
                                         catch (System.ServiceProcess.TimeoutException timeoutException)
                                         {
                                             continue;
                                         }
                                     }
                                 }
                             }
                         }
                         if (!this.DoStopProcess(process))
                         {
                             continue;
                         }
                     }
                     else
                     {
                         this.shouldKillCurrentProcess = true;
                         continue;
                     }
                 }
             }
             catch (Win32Exception win32Exception2)
             {
                 Win32Exception win32Exception1 = win32Exception2;
                 if (!ProcessBaseCommand.TryHasExited(process))
                 {
                     base.WriteNonTerminatingError(process, win32Exception1, ProcessResources.CouldNotStopProcess, "CouldNotStopProcess", ErrorCategory.CloseError);
                     continue;
                 }
             }
             catch (InvalidOperationException invalidOperationException2)
             {
                 InvalidOperationException invalidOperationException1 = invalidOperationException2;
                 if (!ProcessBaseCommand.TryHasExited(process))
                 {
                     base.WriteNonTerminatingError(process, invalidOperationException1, ProcessResources.CouldNotStopProcess, "CouldNotStopProcess", ErrorCategory.CloseError);
                     continue;
                 }
             }
             if (!this.PassThru)
             {
                 continue;
             }
             base.WriteObject(process);
         }
         return;
     }
 }