provisioner/powershell: Use system context env var to set output file path

Fixes #4271
This commit is contained in:
DanHam 2017-01-26 00:03:24 +00:00
parent 22475b39ff
commit 21be983855
1 changed files with 9 additions and 2 deletions

View File

@ -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}} &gt; %TEMP%\{{.TaskName}}.out 2&gt;&amp;1</Arguments>
<Arguments>/c powershell.exe -EncodedCommand {{.EncodedCommand}} &gt; %SYSTEMROOT%\Temp\{{.TaskName}}.out 2&gt;&amp;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`))