Errors Encountered while Trying to Kill a Process

How to kill a user level process (Instead of trying to globally kill a process.) ?

Issue Overview

When trying to kill a process the following error is encountered: Encountered errors while trying to kill a process.

RemoteException wrapping System.AggregateException: Encountered errors while trying to kill a process  ---> RemoteException wrapping System.ComponentModel.Win32Exception: Access is denied


1.      See the attached automation.

2.      The automation does the following

a.      Gets a list of all processes

b.      Gets the users name

                                                              i.      System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(System.Environment.UserDomainName+"\","")

c.       For each process, it checks what the username was when the process started.

                                                              i.      process.StartInfo.Environment("Username")

d.      It also gets the SessionID of the process. (Needed to check that the process is not a service. It is possible that a service was started under a different username. You could get a false match.)

e.      If the Username for a process matches the current user and the processes name matches the specified process and the SessionID for the process is not zero, the automation will try to kill the process.