2

I am creating a schedules task to run just before it's created and deleted after it runs.

I am using the tool, schtasks to create the scheduled task, but i havent found the parameter to run the task "At task creation/modification"

schtasks /create /TN "Install Bpm" /SC ONCE /TR "C:\windows\system32\calc.exe -i silent" /Z

My question is; how can I create a scheduled task via command line, with the trigger “At task creation/modification".

enter image description here

kimo pryvt
  • 431
  • 5
  • 12
  • 24

3 Answers3

1

What you are asking for is really only available using the AT command, as it is designed to perform single-action tasks.

You need to use the /Create to build the task from the command line.

Then you need to /Run the task by its /TN name.

Once the task is complete, the task can call the /Delete command against its own /TN name within the task to clean up after itself.

CoveGeek
  • 186
  • 1
  • 7
1

You cannot create a scheduled task via command line, with the trigger "At task creation/modification". This is a security feature to prevent malwares from spawning new tasks in the background.

Not every options are available with schtasks and it is by design.

scavenger
  • 113
  • 4
0

One can accomplish this using the MSFT_TaskRegistrationTrigger class. Here's a minimal example of how to do so using PowerShell:

Register-ScheduledTask `
    -Action '<PLACEHOLDER>' `
    -TaskName '<PLACEHOLDER>' `
    -Trigger (Get-CimClass `
        -ClassName 'MSFT_TaskRegistrationTrigger' `
        -Namespace 'Root/Microsoft/Windows/TaskScheduler');
Kittoes0124
  • 101
  • 1