I am creating an installer for a Windows application that will be run daily at midnight. I am attempting to schedule the task by running the following command after all files have been installed:
schtasks.exe /create /tn "My Task Name" /xml "path/to/file.xml"
However, no task was created when I ran the installer. I opened command prompt and tried typing in the command manually to see what went wrong, and the only output I received was ERROR: Access is denied.
I followed the suggestions of others and added the /ru
switch, but even after entering the correct password, I still received the access denied error message. I found this answer, which involved modifying the registry using a program called SubInACL, which might work, but would probably be a bad idea, since this would have to be installed and run on all end users' machines just so that the task can be scheduled in the first place. Is there any other way to schedule a task through the command line, or will I have to use something other than Task Scheduler?
Okay, the problem was that running schtasks.exe from the
[Run]
section caused it not to be elevated to the Administrator level. I used theExec()
function in the[Code]
section, and that made it run with Administrator privileges, which solved the problem.