How can I resolve the 'Access is denied' error when using the Kill Process activity?
Issue description:
Users encounter an error when attempting to use the Kill Process activity in UiPath, particularly when trying to terminate processes like Chrome or Edge browsers. The error message often states "Access is denied," which typically occurs when the process is being run by another user on the same machine.
Steps for Troubleshooting:
- Initial Validation
-
- Confirm your versions of UiPath.System.Activities and UiPath.UiAutomation.Activities.
- Determine since when you have been facing this issue.
- Verify if the activity used to work earlier.
- Ensure that browsers are not being launched in elevated (admin) mode.
- Alternative Activities
- Try using the Close Application or Close Window classic activities and check the behavior.
- Log Collection
- In the error message received, click on "Open logs" and share the Studio/Execution logs.
- Replicate the issue and share the Event Viewer logs.
- For guidance on how to obtain these logs, refer to this article - https://uipath-survey.secure.force.com/CaseView/articles/Knowledge/How-to-get-Application-Logs-from-the-Event-Viewer?lang=en_US
Potential Cause:
The issue may be caused by the browser being run by another user.
Resolution:
To address this, try the following:
- Setting Target Property in Kill Activity
- Set the Target property to All and check the behavior.
- If this does not help, try other options like OnlyCurrentUser, OnlyCurrentSession, or OnlyCurrentDesktop.
- Reference: UiPath Kill Process Activity Documentation
- Handling "Access is Denied" Error
- This error usually occurs when a process with the same name is opened for multiple users on the machine. Ensure all other users are logged off and try executing the automation again.
- Designing a Custom Automation
- Create an automation that:
- Gets a list of all processes.
- Retrieves the current user's name using: csharp System.Security.Principal.WindowsIdentity.GetCurrent().Name.Replace(System.Environment.UserDomainName + "\\", "")
- For each process, checks the username when the process started: csharp process.StartInfo.Environment("Username")
- Gets the SessionID of the process to ensure it is not a service.
- If the username matches the current user, the process name matches the specified process, and the SessionID is not zero, the automation will attempt to kill the process.
Final Solution:
If the above options fail, try running the following PowerShell command to kill the process:
taskkill /IM msedge.exe
If successful, use an Invoke PowerShell activity in UiPath to execute this command within your automation.
FYI - https://docs.uipath.com/activities/other/latest/workflow/kill-process
By following these steps, you should be able to resolve the issue with the Kill Process activity in UiPath. If you continue to experience problems, please provide the requested logs and further details for additional assistance.