0

I have a powershell script that needs to be run as admin to set IP addresses. Then I need to run an application as non-admin. As I understand it, this corresponds to the term "elevated rights".

If I simply double click the .exe from the file explorer (not "run as admin"), the app runs as intended without elevated rights.

I have found several tips online on how to accomplish this, however I haven't succeeded with the following commands in my script:

(from How to run exe with/without elevated privileges from PowerShell)

runas /trustlevel:0x20000 "\..\myApp.exe":

this results in an "Internal error" because access is denied to a certain ".lock" file related to an eclipse workspace.

Second approach:

Start-Process -filepath "\..\myApp.exe" -ArgumentsList "-ExecutionPolicy bypass -Scope CurrentUser"

this runs the application but it's run in elevated state.

EDIT: Third approach:

I tried making a second script from where I run

Start-Process -FilePath "\..\myApp.exe"

which I call from my main script using:

Start-Process PowerShell -ArgumentList '-File ""\..\mySecondScript.ps1""' -Verb open

This results in myApp running with elevated rights when its called from within the main script, but without elevated rights when run on powershell on its own.

  • 2
    Possible duplicate of [How to run exe with/without elevated privileges from PowerShell][1] [1]:https://stackoverflow.com/questions/29266622/how-to-run-exe-with-without-elevated-privileges-from-powershell – L8R Apr 01 '22 at 12:51
  • I saw this thread but unfortunately didn't find it helpful. The first approach above is from this link, and the "explorer.exe bug" method I couldn't understand how to apply to my application. – Anton Fahlgren Apr 01 '22 at 13:58

0 Answers0