Archive: Scheduled Tasks on Vista


Scheduled Tasks on Vista
I'm currently using the Scheduled Task Plugin http://nsis.sourceforge.net/Scheduled_Tasks,
this works very well on WindowsXP machines.
But on Vista machines the install wizard crashes the first time its ran, and the second time I get the returned value that the task already exists.
I have looked under C:\Windows\Tasks and found the tasks I'm trying to add are there with the .job extension.
But these do not work.

From reading MSDN I see that Vista uses Task Scheduler v2.0 where'as previous versions of Windows used Task Scheduler v1.0.

Does anyone have any script code or plugins that will create a task for Vista using the Task Scheduler v2.0 ?

Or am I going to have to read more about NSIS to try to do this myself (that's gonna take ages).

Thanks to anyone that can help.


For a quick solution, it'd probably be simplest to write a plug-in that'd add the task. Base it on Examples\Plugin. If not, that script will have to be fixed so it works on Vista as well.


Ok, I realize it's an old thread...

Anyone made any headway on this issue yet? The script http://nsis.sourceforge.net/Scheduled_Tasks hasn't been updated nor any plugins made (that I'm aware of).


The Vista v2 api has a flag called TASK_COMPATIBILITY_V1, so I assume the old api should still work. Could there be a bug with the code on the wiki?

Quoting AmitavaS - MSFT (http://blogs.msdn.com/amitava/) @ http://social.msdn.microsoft.com/For...-337d371d6756/

The ItaskScheduler 1.0 Interface is supported in Server 2008, and Vista. However, the tasks used by Vista and Server 2008 are accessed through the Itask Scheduler 2.0 Interface. Which means that manually scheduled tasks will not enumerate or appear when using the 1.0 interface.
This of course does not mean it actually works.

What if you try using at.exe from XP on Vista?

If it turns out that the v1 api is broken on Vista, then someone will need to write a v2 version

Originally posted by Anders
What if you try using at.exe from XP on Vista?
Yes, my NSIS code regarding creating a scheduled task, which works on Windows 2000, XP, 2003 does not appear to work on Vista x86.

I was not talking about NSIS code there, I'm talking about AT.EXE that ships with XP. Take a copy of it from XP and try it on Vista


Oh the old AT command. I'm using the NSIS scheduled task code because the AT command doesn't provide me enough options/configuration that I need.


well, at this point we just need to know if the v1 api works or not


Just tested. Yes, Vista x86 still comes with the AT command and it does work.


After some more digging, seems Vista has a new tool to manage the scheduled tasks: schtasks.

Also, since now one can export/import Scheduled tasks via XML files, I should be able to accomplish what I need. Export an XML file, use NSIS to modify various fields and then re-import via schtasks.


Originally posted by BSOD2600
Just tested. Yes, Vista x86 still comes with the AT command and it does work.
I know it does, but I wanted you to COPY at.exe from XP and try that version on a Vista machine

Originally posted by Anders
I know it does, but I wanted you to COPY at.exe from XP and try that version on a Vista machine
Alright, copied over the XP AT.exe to Vista. Verified with sysinternals process monitor that it used the XP AT.exe to successfully create a scheduled task.

I probably should have replied to this ages ago.

I don't know if the Scheduled Task plugin has been changed, and I don't know anything about AT.exe (so I'm not really helping at all here).

But the way I got my tasks created was to get the Windows Version (http://nsis.sourceforge.net/Get_Windows_version), if it was "Vista" then I created the task using SchTasks.exe, else I used the Plugin.

SchTasks appears to be able to configure tasks with the same options that TaskScheduler in Control Panel can.


For anyone who comes across this thread and is interested, here's my SchTasks code to create a task that runs every day at a specified time:

 StrCpy $strCmdLine "SCHTASKS /Create /RU UserName /RP Password /SC DAILY /TN TaskName \
/TR $\"'$INSTDIR\File.exe'$\" /ST $strStartHour:$strStartMin /SD 01/01/2008 /IT /F /MO 1"

nsExec::Exec '$strCmdLine'
Pop $0
StrCpy $cmdLineResult $0 1 0
StrCmp $cmdLineResult "0" Cmd2Success CmdFailed