provisioner/powershell: Use system context env var to set output file path
Fixes #4271
This commit is contained in:
parent
22475b39ff
commit
21be983855
|
@ -14,7 +14,7 @@ type elevatedOptions struct {
|
|||
|
||||
var elevatedTemplate = template.Must(template.New("ElevatedCommand").Parse(`
|
||||
$name = "{{.TaskName}}"
|
||||
$log = "$env:TEMP\$name.out"
|
||||
$log = "$env:SystemRoot\Temp\$name.out"
|
||||
$s = New-Object -ComObject "Schedule.Service"
|
||||
$s.Connect()
|
||||
$t = $s.NewTask($null)
|
||||
|
@ -53,7 +53,7 @@ $t.XmlText = @'
|
|||
<Actions Context="Author">
|
||||
<Exec>
|
||||
<Command>cmd</Command>
|
||||
<Arguments>/c powershell.exe -EncodedCommand {{.EncodedCommand}} > %TEMP%\{{.TaskName}}.out 2>&1</Arguments>
|
||||
<Arguments>/c powershell.exe -EncodedCommand {{.EncodedCommand}} > %SYSTEMROOT%\Temp\{{.TaskName}}.out 2>&1</Arguments>
|
||||
</Exec>
|
||||
</Actions>
|
||||
</Task>
|
||||
|
@ -81,5 +81,12 @@ do {
|
|||
}
|
||||
} while (!($t.state -eq 3))
|
||||
$result = $t.LastTaskResult
|
||||
if (Test-Path $log) {
|
||||
try {
|
||||
Takeown /F $log | Out-Null
|
||||
Icacls $log /Grant:r Administrators:F /c /q 2>&1 | Out-Null
|
||||
Remove-Item $log -Force -ErrorAction SilentlyContinue | Out-Null
|
||||
} catch { $Global:Error.RemoveAt(0) }
|
||||
}
|
||||
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($s) | Out-Null
|
||||
exit $result`))
|
||||
|
|
Loading…
Reference in New Issue