I have a code extract that I want to run via an Invoke Code activity, but I need to execute this as a different user to that running the main process.
Can anybody assist with a methodology to do this.
The code is as below (FolderPath and UserAccount are Arguments passed to the Code)
Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
Dim FolderAcl As System.Security.AccessControl.DirectorySecurity = FolderInfo.GetAccessControl()
FolderAcl.AddAccessRule(New System.Security.AccessControl.FileSystemAccessRule(UserAccount, System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.InheritanceFlags.ContainerInherit Or System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow))
You can leverage PowerShell scripts to run code as a different user. PowerShell allows you to use the
Start-Process cmdlet with the
-Credential parameter to execute code with different user credentials. You can use the “Invoke Power Shell” activity in UiPath to run PowerShell scripts.
you can use the “Start Process” activity in UiPath and specify the “Username” and “Password” properties to run the process as a different user.
I’m not a coder myself and grabbed the bit of code I’m using from another forum. Ideally we are trying to keep away from PS scripts so, if you dont mind, as I’ve not used the Start Process activity before, would be grateful if you could provide simple example for me to execute my code.
Running code as a different user within a UiPath process is not straightforward because UiPath activities run within the context of the user who initiated the process. To execute code as a different user, you’d typically need to run the code in a separate process or script that is launched with different credentials