Score:1

Syntax for creating SCHTASK.EXE tasks to run batch files that take parameters

cd flag

I have a set of older batch files that scheduled the running of some maintenance tasks for a database that I look after. They used the AT command. The database has been moved to Windows server 2016 where the AT command has been deprecated. I want to use SCHTASKS.EXE instead but I am having some challenges.

The set of maintenance tasks fall into three separate batch files Ibak1.bat Ibak2.bat and Ibak3.bat.

There is also a Ibak0.bat that schedules each of these Ibak1 to Ibak3 batch files to run at different times.

Ibak0.bat passes a bunch of parameters to Ibak1, Ibak2, and Ibak3. For the sake of my questions, however, we can focus just on Ibak0.bat and Ibak1.bat. Ibak2 and Ibak3 work the same way with variations of the same kind of parameters.

My questions are:

Q1: Can a batch file be scheduled to run with SCHTASKS.EXE?

Q2: With the AT command you had to specify the target batch file to run like this:

at %6 /interactive /every:M,T,W,Th,F,S,Su cmd /c "%5Ibak1.bat %1 %2 %3 %4 "

Does "cmd /c" also need to be specified with SCHTASKS when scheduling batch files?

Q3: When would I use the /IT parameter? None of the batch files require user interaction except that they do echo output to a log file.

Q4: As you can see there are many parameters passed from Ibak0.bat to Ibak1.bat. What is the syntax for passing parameters?

Following are all the variations of syntax that I have tried. I can't, for the life of me, create a schedule task, or in the some cases (Attempt 3, 10, and 14) where I did successfully create the task a command window flashed for an instant but nothing indicated that the task ran properly.

 Atempt   1: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR "'%5Ibak1.bat' '%1' '%2' '%3' '%4' "        /ST %6 /IT /SC DAILY  Outcome: invalid argument         
 Atempt   2: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR   %5Ibak1.bat %1 %2 %3 %4                   /ST %6 /IT /SC DAILY  Outcome: invalid argument         
 Atempt   3: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR  "%5Ibak1.bat %1 %2 %3 %4"                  /ST %6 /IT /SC DAILY  Outcome: scheduled but did not run. cmd opens but closes immediately.         
 Atempt   4: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR '"%5Ibak1.bat" %1 %2 %3 %4'                 /ST %6 /IT /SC DAILY  Outcome: can't remember         
 Atempt   5: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR  "%5Ibak1.bat" %1 %2 %3 %4                  /ST %6 /IT /SC DAILY  Outcome: invalid argument         
 Atempt   6: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR  "%5Ibak1.bat" /%1 /%2 /%3 /%4              /ST %6 /IT /SC DAILY  Outcome: invalid argument
 Atempt   7: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR  "%5Ibak1.bat" \%1 \%2 \%3 \%4              /ST %6 /IT /SC DAILY  Outcome: invalid argument
 Atempt   8: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR cmd /c "%5Ibak1.bat %1 %2 %3 %4   "         /ST %6 /IT /SC DAILY  Outcome: invalid argument  
 Atempt   9: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR cmd "%5Ibak1.bat %1 %2 %3 %4   "            /ST %6 /IT /SC DAILY  Outcome: invalid argument  
 Attempt 10: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR "cmd.exe /c \"%5Ibak1.bat %1 %2 %3 %4 \" "  /ST %6 /IT /SC DAILY  Outcome: scheduled but did not run. cmd opens but closes immediately.    
 Attempt 11: SchTasks /CREATE /TN Ibak1.Make_Copy_%1 /TR "cmd.exe /k \"%5Ibak1.bat %1 %2 %3 %4 \" "  /ST %6 /IT /SC DAILY  Outcome: C:\TNS not recognized as a program    
 Attempt 12: SchTasks /CREATE /TN Ibak1.Make_Copy_%3 /TR c:\TNS\(data)\IBAK\Ibak1.bat %1 %2 %9       /ST %6 /IT /SC DAILY  Outcome: Invalid argument/option 
 Attempt 13: SchTasks /CREATE /TN Ibak1.Make_Copy_%3 /TR "c:\TNS\(data)\IBAK\Ibak1.bat %1 %2 %9 "    /ST %6 /IT /SC DAILY  Outcome: ERROR: The parameter is incorrect.
 Attempt 14: SchTasks /CREATE /TN Ibak1.Make_Copy_%3 /TR "cmd.exe /k \"c:\TNS\(data)\IBAK\Ibak1.bat %1 %2 %9 \" " /ST %6 /IT /SC DAILY Outcome: C:\TNS not recognized as a program

A bit about the params in case that is important:

 Parameters : %1 Live database file being copied.
 Attempts     %2 Path to database file. Include terminating "\".
 1 to 11      %3 Server Volume or share name to receive copy of DB file being backed up. Do *NOT* Include terminating "\".
              %4 Server Path to copy %2%1 to. Include terminating "\" but no drive letter.
              %5 Path to batch file collection. Include terminating "\" and drive letter.
              %6 Time Ibak1.bat is scheduled to run. Use 24 hour format.
              %7 Time Ibak2.bat is scheduled to run. Use 24 hour format.
              %8 Time Ibak3.bat is scheduled to run. Use 24 hour format. 
              

Because I thought there might be some issue passing folder names separately from file names for Attempts 12 onward I used full path names for files. Here is how I rearranged the parameters:

 Parameters : %1 Live FDB file being copied (full path).
 Attempts     %2 Live FDB file copy target (full path). 
 12 onwards   %3 FDB identifier (ex.: WILSONS, VTT, SMITH)
              %4 RESERVED
              %5 RESERVED
              %6 Time ibak1.bat is scheduled to run. Use 24 hour format.
              %7 Time ibak2.bat is scheduled to run. Use 24 hour format.
              %8 Time ibak3.bat is scheduled to run. Use 24 hour format.
              %9 Log file name (full path).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.