While running powershell using invoke activity it throws exception "windows powershell run as administrator"

Invoke Power Shell: Access is denied. To run this cmdlet, start Windows PowerShell with the “Run as administrator” option.

1 Like

Hi @Mahashankaripazhani

Supported by this thread, I was able to make a simple process:

image

However, running this will prompt the UAC (which would need to be disabled for this to work, which is highly not recommanded).

Actually, there is a solution to it :slight_smile: (credit to out of our awesome uipathers). See his explanation below:

I use the activity invoking a script. If the script tries to invoke:
Start-Process notepad.exe -Verb runAs
then the UAC dialog will appear defeating the purpose.

If the script instead says:
$credential = New-Object System.Management.Automation.PsCredential(“admin”, (ConvertTo-SecureString “Passw0rd1” -AsPlainText -Force))
Start-Process notepad.exe -Credential $credential

then all is well and the process is run as an administrator without a UAC dialog coming up.

This method requires a prior relaxation of the ability to execute scripts using “Set-ExecutionPolicy”.

Link to .xaml and ps1 script here:
run_as_admin.zip (1.7 KB)

3 Likes

Hi @loginerror ,

can you please help with the packages that you have used in that particular process? Ive been trying t use this xaml, but it shows invalid activity

Hi ,

I tried running your process. It throws me this error.

image

Hi @shreyaank

You’re right, you need to make sure the path of the invoke activity is in the correct folder. By default the zip didn’t contain that folder, whoops :smiley:

This change should fix it:
imageimage

1 Like

Hello
@Hiba_B
Can you help me please :heart_eyes:
when i run the script i get the following message but user and password are good. Do i need some conf before ? on my powershell i set some ExecutionPolicy like process and currentuser as Bypass.
image