Start-ChocolateyProcessAsAdmin

Start-ChocolateyProcessAsAdmin

Start-ChocolateyProcessAsAdmin

:choco-info: NOTE

Administrative Access Required.

Runs a process with administrative privileges. If -ExeToRun is not specified, it is run with PowerShell.

Syntax

Start-ChocolateyProcessAsAdmin `
  [-Statements <String[]>] `
  [-ExeToRun <String>] `
  [-Elevated] `
  [-Minimized] `
  [-NoSleep] `
  [-ValidExitCodes <Object>] `
  [-WorkingDirectory <String>] `
  [-SensitiveStatements <String>] `
  [-IgnoredArguments <Object[]>] [<CommonParameters>]

Notes

This command will assert UAC/Admin privileges on the machine.

Will automatically call Set-PowerShellExitCode to set the package exit code in the following ways:

  • 4 if the binary turns out to be a text file.
  • The same exit code returned from the process that is run. If a 3010 is returned, it will set 3010 for the package.

Aliases Start-ChocolateyProcess and Invoke-ChocolateyProcess.

Aliases

Invoke-ChocolateyProcess Start-ChocolateyProcess

Examples

EXAMPLE 1

Start-ChocolateyProcessAsAdmin -Statements "$msiArgs" -ExeToRun 'msiexec'

EXAMPLE 2

Start-ChocolateyProcessAsAdmin -Statements "$silentArgs" -ExeToRun $file

EXAMPLE 3

Start-ChocolateyProcessAsAdmin -Statements "$silentArgs" -ExeToRun $file -ValidExitCodes @(0,21)

EXAMPLE 4


# Run PowerShell statements
$psFile = Join-Path "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" 'someInstall.ps1'
Start-ChocolateyProcessAsAdmin "& `'$psFile`'"

EXAMPLE 5

# This also works for cmd and is required if you have any spaces in the paths within your command
$appPath = "$env:ProgramFiles\myapp"
$cmdBatch = "/c `"$appPath\bin\installmyappservice.bat`""
Start-ChocolateyProcessAsAdmin $cmdBatch cmd
# or more explicitly
Start-ChocolateyProcessAsAdmin -Statements $cmdBatch -ExeToRun "cmd.exe"

Inputs

None

Outputs

None

Parameters

-Statements [<String[]>]

PropertyValue
Aliases
Required?false
Position?1
Default Value
Accept Pipeline Input?false

-ExeToRun [<String>]

PropertyValue
Aliases
Required?false
Position?2
Default Valuepowershell
Accept Pipeline Input?false

-Elevated

PropertyValue
Aliases
Required?false
Position?named
Default ValueTrue
Accept Pipeline Input?false

-Minimized

PropertyValue
Aliases
Required?false
Position?named
Default ValueFalse
Accept Pipeline Input?false

-NoSleep

PropertyValue
Aliases
Required?false
Position?named
Default ValueFalse
Accept Pipeline Input?false

-ValidExitCodes [<Object>]

PropertyValue
Aliases
Required?false
Position?named
Default Value@(0)
Accept Pipeline Input?false

-WorkingDirectory [<String>]

PropertyValue
Aliases
Required?false
Position?named
Default Value
Accept Pipeline Input?false

-SensitiveStatements [<String>]

PropertyValue
Aliases
Required?false
Position?named
Default Value
Accept Pipeline Input?false

-IgnoredArguments [<Object[]>]

PropertyValue
Aliases
Required?false
Position?named
Default Value
Accept Pipeline Input?false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters http://go.microsoft.com/fwlink/p/?LinkID=113216 .

Function Reference

:choco-info: NOTE

This documentation has been automatically generated from Import-Module "$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1" -Force; Get-Help Start-ChocolateyProcessAsAdmin -Full.

View the source for Start-ChocolateyProcessAsAdmin