Reputation: 2943
I know there are bunch of example on MSDN about windows task scheduling , but they all(except logon/boot time) require users credentials for saving the task to root folder and hence successfully registering the task.
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(_bstr_t(pszName)), //USERNAME
_variant_t(_bstr_t(pszPwd)), //PASSWORD
TASK_LOGON_PASSWORD,
_variant_t(L""),
&pRegisteredTask);
But I have seen some softwares that schedule tasks on user system without prompting user for credentials.
Just want to know how is it achieved? Builting//Administrator
thing doesn't seem to work for scheduling daily tasks.
What is the other way out? Any help is appreciated.
Upvotes: 1
Views: 1202
Reputation: 2943
Since its been more than 2 weeks and no answer is received , I am answering my way around to solve this problem.
To schedule the tasks without user account name and password , we can take the leverage of windows Schtasks.exe present in System32 directory.
You can simply make your program (which should be running with admin rights) to execute this Schtasks.exe with proper parameters to schedule your Daily, Weekly and Monthly tasks.
For example : The following command schedules a daily task to run at time HH:mm and trigger an exe every 1 hour for the duration of 24 hours.
Schtasks.exe /CREATE /TN "MyDailyTask" /TR "C:/path/to/trigger/app.exe" /F /SC DAILY /SD mm/dd/yyyy /ST HH:mm /RI 60 /DU 24:00
And as you can see we dont need to give username and password as long as our application is running with admin access.
Upvotes: 3