0

I am running an installer using PowerShell. I called the script installer.ps1 which is called by another script as follows:

#master.ps1
C:\\Path\\to\\script\\installer.ps1 -Verb Runas -PassThru |Out-Null

The master.ps1 calls the installer script in the following matter; however, the installer script calls two executables. Executable A and executable B both of which a UAC popup window appears on the screen. For example, this is how the code for installer looks like:

#installer.ps1
Start-Process -Wait C:\\Path\\to\\A.exe -Verb Runas -PassThru | Out-Null

This is just a MWE but I ideally have n-th Start-Process'es for the installation of various executables. Is there any way to make A.exe inherit the admin privileges from installer running as admin or do I need to do

-Verb Runas

each time I would like an exe to run as admin?

I am hoping to make all the executables that I am running in the installer script receive the admin privileges that the installer.ps1 script is receiving from the master.ps1. Please let me know if my logic is flawed in any way or if I am incorrect in my assertions of how the admin privileges are being passed through PowerShell.

I was recently reading up on the docs for PowerShell and was wondering if Invoke Expression

Invoke-Expression
      [-Command] <String>
      [<CommonParameters>]

Would suffice instead of the Start-Process? However I still need the executable to finish before the next one can start. I will keep researching and adding to the post.

I found this question helpful.

EnlightenedFunky
  • 303
  • 1
  • 13

1 Answers1

1

Your understanding is correct in that child processes in Windows will inherit the privileges. If the parent runs elevated, the child will also run elevated. It is not necessary to specify the -Verb RunAs parameter for child processes when the parent already runs elevated. I like to test these things with an easy command which I know requires admin privileges, see the examples below.

Open powershell without admin

Start-Process cmd.exe
ipconfig /registerdns
The requested operation requires elevation.

Open powershell with admin, enter password in UAC

Start-Process cmd.exe
ipconfig /registerdns
Registration of the DNS resource records for all adapters of this computer has been initiated. Any errors will be reported in the Event Viewer in 15 minutes.
David Trevor
  • 794
  • 1
  • 7
  • 22