Archive: how to add scheduled task, or is it possible?


how to add scheduled task, or is it possible?
what if i wanted myapp.exe to be launched every monday at 09:00 ?


A little forum search came up with:

http://forums.winamp.com/showthread....light=schedule


That would be a good plugin for NSIS.
Do you think it will be made?

-Stu


Not by me on the near couple of weeks.


At NT/W2k/Xp system there is command AT.EXE.
at.exe 9:00 /every:monday "c:\test.exe"


Job could be done using updated system plugin (as soon as exehead will be updated too, for plugin look at "Exehead & Ole" thread). I've included source file with function and use example (since it will be hard to extract information from this page :)

Usage:

push "My Task"
push "My Task Comment"
push "c:\Working Dir\My Task Program.exe"
push "c:\Working Dir"
push "My Program Args"
; what that's structure means? look thru attached nsi file, that's information tooks to many place
push "*(&l2, &i2 0, &i2 2003, &i2 9, &i2 3, &i2 0, &i2 0, &i2 0, &i2 9, &i2 0, i 0, i 0, i 0, i 2, &i2 1, &i2 0x2, &i2 0, i 0, &i2 0) i.s"
Call CreateTask
Pop $0
MessageBox MB_OK "CreateTask result: $0"

Realization and TIME_TRIGGER structure description are at attached nsi file.


well, i got first example working fine, but i didn't manage to do it with the other one :(
tnx anyway


first example???? I've posted only one...

Oh. you mean at.exe. :)

To utilize second one (it will work at win95-winxp) you'll need the latest CVS (as soon as Kichik will update it for compatibility with system plugin ;).

So... All together: KICHIK! KICHIK!! KICHIK!!!


well i still didn't understand second example, but i have a question with the first one. By default this command line
'at.exe 9:00 /every:monday "c:\test.exe"'
gives a name for the scheduled task "at1". is it possible to give job different name?


For the second one you need the latest CVS version. As for the name of the task with the first one, if to believe to at.exe /?, you can't.


Somebody checked it beside me? Kichik could you please? ;)


Yes, it works.


ok got it:)


Just a system update.

release 5, 11 september 2003.
1. u flag - unload dll after procedure call.
2. some changes to asm to turn on Whole Program Optimization.
3. Dll shrinked for 1 kb.


Uploaded, thanks.


Before delving deeper into this plug-in, does it use the Task Scheduler API?

If so, does it have the same limitation as XP's command line schtasks?

By limitation I mean the inability to schedule a task with an empty password (in addition to the fact that it's not available in XP Home).


Answering myself:

Originally posted by nsnb
does it use the Task Scheduler API?
Yes! It creates the familiar job files in %WINDIR%\Tasks.

Originally posted by nsnb
If so, does it have the same limitation as XP's command line schtasks?
Yes. If the password for the account is empty, then the task would not start and logs the following error:
The attempt to retrieve account information for the specified task failed; therefore, the task did not run. Either an error occurred, or no account information existed for the task.
The specific error is:
0x8004130f: No account information could be found in the Task Scheduler security database for the task indicated.
The behavior of the existing "NSIS Scheduled Tasks" in my test system (XP SP2) is frustratingly unexplainable: The above error would occur if the scheduled job is produced by the script, but if the same exact task is opened via GUI and interactively uncheck-then-check the box "Run only if logged on", then the task would start.

Any explanation for that? How do I even begin to troubleshoot a problem like this (aside from looking at the log file and reading what I quoted above)?

Thanks.

Originally posted by nsnb
Any explanation for that? How do I even begin to troubleshoot a problem like this (aside from looking at the log file and reading what I quoted above)?
This problem is driving me crazy. I've combed the web and found many many posts describing a situation similar to what I described. For example:

http://forums.winamp.com/showthread.php?t=225449

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

http://social.msdn.microsoft.com/For...d-5f1af694ae72

But none of them would provide a clue as to why both NSIS flavors (the original NOT providing username/password & the latest one providing them) will not work on my test system.

As I was about to give up, I discovered that if I create a password for the Administrator account (under which I am trying to set the scheduled task), and provide both the correct username and password, then the test NSIS script would finally succeed.

Nice, but isn't the existence of TASK_FLAG_RUN_ONLY_IF_LOGGED_ON (0x2000) supposed to answer exactly a case in which we DON'T want to provide a password in the script?

Something is not right here, and I don't know whether it's a bug in Windows, a bug in the MSDN documentation, or a bug in the "Scheduled Tasks" script for NSIS.

Or a bug in my brain. :stare:

Could you please help?

This is a secretly undocumented feature by Microsoft. You can't schedule tasks on a Windows account with administrator privileges that has no password.


Originally posted by ronca
This is a secretly undocumented feature by Microsoft. You can't schedule tasks on a Windows account with administrator privileges that has no password.
What??? This doesn't make sense. If Microsoft wanted to prohibit an Admin account with an empty password, it would have been disabled across the board, not only for the Task Scheduler.

Besides, Google's Chrome installed quite a few such (working!) scheduled tasks on my test machine having an Admin account with an empty password. Apple's iTunes did the same thing.

Also, created a scheduled task from the GUI (using the "Run only if logged on" checkbox) also works.

The problem must by lying elsewhere. I am becoming convinced that there is a bug in both NSIS "Scheduled Tasks" available scripts.

Has anyone (beside me) tested these scripts on an Admin account with an empty password?

Originally posted by nsnb
What??? This doesn't make sense.
Of course it doesn't make sense but that's Microsoft. You don't have to believe me. I don't know if you discovered this already but in task scheduler you can't enter a path with spaces in it. For example if you have something in "C:\Program Files" you must use C:\Progra~1 instead. Makes sense? Of course not but that's Microsoft.

Originally posted by ronca
I don't know if you discovered this already but in task scheduler you can't enter a path with spaces in it. For example if you have something in "C:\Program Files" you must use C:\Progra~1 instead. Makes sense? Of course not but that's Microsoft
It turns out you were correct.

I was hoping that by using the NSIS "Scheduled Tasks" script I could avoid prompting the user for entering his password but since it needs the user password, too, I ended up using nsExec::Exec schtasks /create instead, which is documented at least and slightly more predictable.