Archive: Add parameter to a new Task in Task Schedule with NSIS


Add parameter to a new Task in Task Schedule with NSIS
hi,

i want to put some parameter for a new Task in Task Scheduler.

if i write so:

ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$0" /C if 1==1 SchTasks /Create /SC ONLOGON /TN "ATask" /TR "C:\PROGRA~2\test\test.exe -j 1 -t 30 min"'


It works.

And if i write so:

Var /Global tempVar
StrCpy $tempVar "C:\PROGRA~2\test\test.exe"
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$0" /C if 1==1 SchTasks /Create /SC ONLOGON /TN "ATask" /TR "$tempVar -j 1 -t 30 min"'


It also works fine.

But if i write so:
Var /Global tempVar
StrCpy $tempVar $ShortName # $ShortName has this value => "C:\PROGRA~2\test\test.exe"
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$0" /C if 1==1 SchTasks /Create /SC ONLOGON /TN "ATask" /TR "$tempVar -j 1 -t 30 min"'


But It does NOT work!!!

it only add "ATask" in Task Scheduler without parameter.

How can i put some parameter to "ATask" in NSIS?

Are you sure $ShortName = "C:\PROGRA~2\test\test.exe"?
Check with a MessageBox, it should work the way you use it.


BTW, are the double quotes in the string value?
That would explain no parameters.


Yes, it is checked with MessageBox.

And there is no double quotation in String.

But, i have found the solution.

if i use "ExecWait" like following, then it works.

ExecWait 'SchTasks /Create /SC ONLOGON /TN "ATask" /TR "$tempVar -j 1 -t 30 min"'