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
Resolution
- Automation should do the following
- Gets a list of all processes
- Gets the users name
- System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(System.Environment.UserDomainName+"\","")
- For each process, it checks what the username was when the process started.
- process.StartInfo.Environment("Username")
- 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.)
- 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.