CMD command (not a application/script) as a action in schtasks

Eni Nede 21 Reputation points
2022-02-17T19:21:32.427+00:00

Hello everyone!

Is it possible to release CMD command (but not as a aplication or script) straight away from task scheduler, like (or similiar):

"schtasks /create /sc DAILY /mo 1 /st Time.Value /tn Backup_name /tr " +

and instead of providing application name, to include another cmd command, like:

"xcopy \rawdata \reports /u"

and as a whole:

schtasks /create /sc DAILY /mo 1 /st Time.Value /tn Backup_name /tr xcopy \rawdata \reports /u

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,408 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 32,246 Reputation points
    2022-02-17T20:05:17.113+00:00

    "Xcopy" is not a "cmd command", it is a program, C:\Windows\System32\xcopy.exe. "Dir" is a "cmd command". You can use where.exe to search the system path folders for an executable name.

    C:\>where xcopy
    C:\Windows\System32\xcopy.exe
    
    C:\>where dir
    INFO: Could not find files for the given pattern(s).
    
    C:\>where where
    C:\Windows\System32\where.exe
    

    You can schedule xcopy because it is a program. You have to use quotes for the /tr value to be able to pass arguments to the program.

    schtasks /create /sc DAILY /mo 1 /st Time.Value /tn Backup_name /tr "xcopy.exe c:\rawdata c:\reports /u"
    

    You cannot schedule "dir" by itself because it is a "cmd command"

    schtasks /create /sc DAILY /mo 1 /st Time.Value /tn Backup_name /tr "cmd.exe /c dir > C:\temp\DirOutput.txt"
    
    0 comments No comments

0 additional answers

Sort by: Most helpful