Skip to content

Commit d8da04e

Browse files
author
David Swan
committed
(IAC-732) - implement `Run only when user is logged on
1 parent 7ce1510 commit d8da04e

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

REFERENCE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Please also note that Puppet must be running as a privileged user
6666
in order to manage `scheduled_task` resources. Running as an
6767
unprivileged user will result in 'access denied' errors.
6868

69+
If a user is specified without an accompanying password the
70+
task will be created with `Run only when user is logged on`
71+
specified.
72+
6973
Default value: system
7074

7175
##### `compatibility`

lib/puppet/type/scheduled_task.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@
7575
7676
Please also note that Puppet must be running as a privileged user
7777
in order to manage `scheduled_task` resources. Running as an
78-
unprivileged user will result in 'access denied' errors."
78+
unprivileged user will result in 'access denied' errors.
79+
80+
If a user is specified without an accompanying password the
81+
task will be created with `Run only when user is logged on`
82+
specified."
7983

8084
defaultto :system
8185

lib/puppet_x/puppetlabs/scheduled_task/task.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ def set_account_information(user, password)
349349
@definition.Principal.LogonType = TASK_LOGON_TYPE::TASK_LOGON_SERVICE_ACCOUNT
350350
else
351351
@definition.Principal.UserId = user
352-
@definition.Principal.LogonType = TASK_LOGON_TYPE::TASK_LOGON_PASSWORD
352+
@definition.Principal.LogonType = if @task_password
353+
TASK_LOGON_TYPE::TASK_LOGON_PASSWORD
354+
else
355+
TASK_LOGON_TYPE::TASK_LOGON_INTERACTIVE_TOKEN
356+
end
353357
end
354358

355359
true

spec/acceptance/should_create_task_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,53 @@
123123
end
124124
end
125125

126+
it 'creates a task with a username: taskscheduler_api2' do
127+
pp = <<-MANIFEST
128+
scheduled_task {'#{taskname}':
129+
ensure => present,
130+
command => 'c:\\\\windows\\\\system32\\\\notepad.exe',
131+
arguments => "foo bar baz",
132+
working_dir => 'c:\\\\windows',
133+
user => '#{username}',
134+
trigger => {
135+
schedule => daily,
136+
start_time => '12:00',
137+
},
138+
}
139+
MANIFEST
140+
apply_manifest(pp, catch_failures: true)
141+
142+
# Verify the task exists
143+
query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
144+
run_shell(query_cmd) do |result|
145+
expect(result.stdout).to match(%r{#{username}})
146+
end
147+
end
148+
149+
it 'creates a task with a username: win32_taskscheduler' do
150+
pp = <<-MANIFEST
151+
scheduled_task {'#{taskname}':
152+
ensure => present,
153+
command => 'c:\\\\windows\\\\system32\\\\notepad.exe',
154+
arguments => "foo bar baz",
155+
working_dir => 'c:\\\\windows',
156+
user => '#{username}',
157+
trigger => {
158+
schedule => daily,
159+
start_time => '12:00',
160+
},
161+
provider => 'win32_taskscheduler'
162+
}
163+
MANIFEST
164+
apply_manifest(pp, catch_failures: true)
165+
166+
# Verify the task exists
167+
query_cmd = "schtasks.exe /query /v /fo list /tn #{taskname}"
168+
run_shell(query_cmd) do |result|
169+
expect(result.stdout).to match(%r{#{username}})
170+
end
171+
end
172+
126173
it "updates a task's credentials: win32_taskscheduler" do
127174
pp = <<-MANIFEST
128175
scheduled_task {'#{taskname}':

0 commit comments

Comments
 (0)