adnanshaheen
1st October 2012 15:29 UTC
Add task using schtasks from nsis
Hi All,
I am trying to add a task to task scheduler, using my nsis script.
ExecWait '$SYSDIR\schtasks.exe /Create /TN MyAppTask /SC ONSTART /TR "$INSTDIR"\MyApp.exe /RU System'
It adds a task but there is a problem with the task.
schtasks add the task with application name "$INSTDIR"\MyApp.exe
You people must know, here, $INSTDIR is "C:\Program Files".
Now the problem is, schtasks add the task with application "C:\Program" and arguments to the application as "Files\MyApp.exe". Which is definitely incorrect.
I want the application "C:\Program Files\MyApp.exe" to be the task.
Any help is highly appreciated.
Regards:-
Adnan
MSG
1st October 2012 15:42 UTC
Try "$INSTDIR\MyApp.exe"?
adnanshaheen
1st October 2012 15:54 UTC
Same result
Anders
1st October 2012 16:42 UTC
Example @ http://www.microsoft.com/resources/d....mspx?mfr=true uses quoted path so it should be supported...
adnanshaheen
1st October 2012 16:55 UTC
It should be, but it seems not.
Why don't you give it a small try. You will find out.
demiller9
1st October 2012 18:45 UTC
The page that Anders recommends has an example:
schtasks /change /tn Notepad /tr "c:\program files\Internet Explorer\iexplore.exe" /ru DomainX\Admin01
You should use their syntax with single quotes around the entire line for ExecWait to take the line as one parameter.
ExecWait '$SYSDIR\schtasks /create /tn MyAppTask /sc onstart /tr "$INSTDIR\MyApp.exe" /ru SYSTEM'
If that still doesn't work, try using the short file name version (8.3) of the path to your program. It won't need quotes that way.
adnanshaheen
2nd October 2012 07:36 UTC
ok, thanks. But this doesn't work either.
How to get the short file name using the nsi script.
Because $INSTDIR can be changed by user during installation.
adnanshaheen
2nd October 2012 09:11 UTC
I guess GetFullPathName /SHORT is the answer here. Thanks Demiller9