Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a powershell script that creates a scheduled task using a call to RegisterTask via the Schedule.Service com object.

Essentially:

$ts = new-object -com Schedule.Service
$ts.Connect()
$rootfolder = $ts.GetFolder("\")
$taskXml = Get-Content "Task.xml"
$rootfolder.RegisterTask("\Maintenance", $taskXml, 6, "LOCAL SERVICE", $null, 5)

This works fine on my local machine (windows 7, and I am a local admin)

When I try this on the machine it will be run on, the RegisterTask call fails with ACCESS_DENIED.

However, if I run a command prompt as administrator, then powershell.exe -file myscript.sps1 it works fine and adds the task.

I have ensured that the user that it is running under has permissions to write to the Tasks folders in %windir% and %windir%/system32

The user is in the Administrators group, which is puzzling, what else do I need to do to give the user the permissions to create scheduled tasks? It seems that just adding them to the local administrators group isn't enough.

EDIT: I have logged onto the server as the user that will be running the script. I can successfully import the xml file into the Task Scheduler UI addin manually.

share|improve this question
    
Did you already create the Maintenance folder? –  Ryan Ries Feb 26 '13 at 0:53
    
No, I didn't need to when running it locally. I also changed the script to create the task in the root folder and get the same issue. –  Matt Feb 26 '13 at 1:01

1 Answer 1

I gave up in the end, couldn't find a way to do this using register tasks, however using schtasks allowed me to import the xml file of the task without the access denied error. I could also use schtasks to import the task to a remote machine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.