winrm-elevated 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f2b2fca8293f26ddc26ca6f68a1d2b69ced5ef8be217aed74600e2acb2857ba
4
- data.tar.gz: acb00e26cab830dac9e99243b45cd2540862126cbc36fea58b291622c013e266
3
+ metadata.gz: e5c9bfe856756ffb48cf79dc0607bf52d9adccb9dd310220337b8410740b8993
4
+ data.tar.gz: 4c12a53e2641725ce24e95c60d5efed248477f6176151ec4920d9d080284d13d
5
5
  SHA512:
6
- metadata.gz: f65ffee1e0df126f9a4c68477213a527c29bf5c7c220adae4dd49bb09c6d2270086a48833f532e4a320d05d0019a3968fedac2e5fa0c673962131694a053a97a
7
- data.tar.gz: 51de3fab0da1486447b18c3996f7ec10640d1e9113142ccbb965da7a33c4b749d76b5965a4c1503bda11e52414d93c6f166399b156120bc141e344372bdc569d
6
+ metadata.gz: 642b27dfba98db6686b52869737ea9876ed6c4e002e878484277851a793d07ddd00193430f946d8141d8d90a1bbd16dd61b8eae51a183f8bb7b5cb8391853376
7
+ data.tar.gz: 46040a6e7f2d8004b76c4f442628776949003d718a46c41f3916ba75942a8a478ce018ab69171e3a885db00aedadb30b9b3789158026a9cb7dea7b47850a65c4
@@ -16,7 +16,7 @@ if($interactive -eq 'true') {
16
16
  $logon_type_xml = "<LogonType>InteractiveTokenOrPassword</LogonType>"
17
17
  }
18
18
 
19
- $task_name = "WinRM_Elevated_Shell"
19
+ $task_name = "WinRM_Elevated_Shell_" + (New-Guid).Guid
20
20
  $out_file = [System.IO.Path]::GetTempFileName()
21
21
  $err_file = [System.IO.Path]::GetTempFileName()
22
22
 
@@ -97,11 +97,13 @@ function SlurpOutput($file, $cur_line, $out_type) {
97
97
 
98
98
  $err_cur_line = 0
99
99
  $out_cur_line = 0
100
+ $timeout = <%= execution_timeout %>
101
+ $startDate = Get-Date
100
102
  do {
101
103
  Start-Sleep -m 100
102
104
  $out_cur_line = SlurpOutput $out_file $out_cur_line 'out'
103
105
  $err_cur_line = SlurpOutput $err_file $err_cur_line 'err'
104
- } while (!($registered_task.state -eq 3))
106
+ } while( (!($registered_task.state -eq 3)) -and ($startDate.AddSeconds($timeout) -gt (Get-Date)) )
105
107
 
106
108
  # We'll make a best effort to clean these files
107
109
  # But a reboot could possibly end the task while the process
@@ -111,6 +113,9 @@ try { Remove-Item $err_file -ErrorAction Stop } catch {}
111
113
  try { Remove-Item $script_file -ErrorAction Stop } catch {}
112
114
 
113
115
  $exit_code = $registered_task.LastTaskResult
116
+
117
+ try { Unregister-ScheduledTask -TaskName $task_name -Confirm:$false } catch {}
118
+
114
119
  [System.Runtime.Interopservices.Marshal]::ReleaseComObject($schedule) | Out-Null
115
120
 
116
121
  exit $exit_code
@@ -33,6 +33,7 @@ module WinRM
33
33
  @interactive_logon = false
34
34
  @shell = Powershell.new(connection_opts, transport, logger)
35
35
  @winrm_file_transporter = WinRM::FS::Core::FileTransporter.new(@shell)
36
+ @execution_timeout = 86_400
36
37
  end
37
38
 
38
39
  # @return [String] The admin user name to execute the scheduled task as
@@ -44,6 +45,9 @@ module WinRM
44
45
  # @return [Bool] Using an interactive logon
45
46
  attr_accessor :interactive_logon
46
47
 
48
+ # @return [Integer] Timeout for the task to be executed
49
+ attr_accessor :execution_timeout
50
+
47
51
  # Run a command or PowerShell script elevated without any of the
48
52
  # restrictions that WinRM puts in place.
49
53
  #
@@ -95,7 +99,8 @@ module WinRM
95
99
  username: username,
96
100
  password: password,
97
101
  script_path: script_path,
98
- interactive_logon: interactive_logon
102
+ interactive_logon: interactive_logon,
103
+ execution_timeout: execution_timeout
99
104
  }
100
105
 
101
106
  b = binding
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winrm-elevated
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shawn Neal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-05 00:00:00.000000000 Z
11
+ date: 2020-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi