diff --git a/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 b/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 index 214a8c6fc5..79455524c2 100644 --- a/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 +++ b/src/chocolatey.resources/helpers/functions/Start-ChocolateyProcessAsAdmin.ps1 @@ -94,6 +94,14 @@ Start-ChocolateyProcessAsAdmin -Statements "$silentArgs" -ExeToRun $file -ValidE $psFile = Join-Path "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" 'someInstall.ps1' Start-ChocolateyProcessAsAdmin "& `'$psFile`'" +.EXAMPLE +# 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" + .LINK Install-ChocolateyPackage diff --git a/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs b/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs index c3b1cbb246..c6dcb2a1bf 100644 --- a/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs +++ b/src/chocolatey/infrastructure.app/templates/ChocolateyInstallTemplate.cs @@ -111,6 +111,12 @@ public class ChocolateyInstallTemplate ## - https://chocolatey.org/docs/helpers-start-chocolatey-process-as-admin #Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes +## To avoid quoting issues, you can also assemble your -Statements in another variable and pass it in +#$appPath = ""$env:ProgramFiles\appname"" +##Will resolve to C:\Program Files\appname +#$statementsToRun = ""/C `""$appPath\bin\installservice.bat`"""" +#Start-ChocolateyProcessAsAdmin $statementsToRun cmd -validExitCodes $validExitCodes + ## add specific folders to the path - any executables found in the chocolatey package ## folder will already be on the path. This is used in addition to that or for cases ## when a native installer doesn't add things to the path. @@ -173,4 +179,4 @@ public class ChocolateyInstallTemplate #{{ChecksumTypex64}} - The checksum type for the 64-bit url | /ct64 "; } -} \ No newline at end of file +}