Skip to content

Commit

Permalink
Set the scheduled task timeout
Browse files Browse the repository at this point in the history
Use the current WinRM operation timeout for the scheduled task timeout
  • Loading branch information
sneal committed Oct 15, 2015
1 parent 7ac1ba4 commit c48387f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/winrm-elevated/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def elevated_shell_script_content
def wrap_in_scheduled_task(script_text, username, password)
ps_script = WinRM::PowershellScript.new(script_text)
"powershell -executionpolicy bypass -file \"#{@elevated_shell_path}\" " \
"-username \"#{username}\" -password \"#{password}\" " \
"-username \"#{username}\" -password \"#{password}\" -timeout \"#{@winrm_service.timeout}\" " \
"-encoded_command \"#{ps_script.encoded}\""
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/winrm-elevated/scripts/elevated_shell.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
param([String]$username, [String]$password, [String]$encoded_command)
param([String]$username, [String]$password, [String]$encoded_command, [String]$timeout)

$task_name = "WinRM_Elevated_Shell"
$out_file = "$env:Temp\winrm_elevated_out.log"
Expand Down Expand Up @@ -37,7 +37,7 @@ $task_xml = @'
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT2H</ExecutionTimeLimit>
<ExecutionTimeLimit>{timeout}</ExecutionTimeLimit>
<Priority>4</Priority>
</Settings>
<Actions Context="Author">
Expand All @@ -53,6 +53,7 @@ $arguments = "/c powershell.exe -EncodedCommand $encoded_command &gt; $out_file

$task_xml = $task_xml.Replace("{arguments}", $arguments)
$task_xml = $task_xml.Replace("{username}", $username)
$task_xml = $task_xml.Replace("{timeout}", $timeout)

$schedule = New-Object -ComObject "Schedule.Service"
$schedule.Connect()
Expand Down

0 comments on commit c48387f

Please sign in to comment.