Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create and Manage Scheduled Tasks in Windows Using Task Scheduler and Command Line

Scheduled tasks, known as "Tarefa Agendada" in Portuguese, are a crucial feature in Windows that allows users to automate tasks, such as running scripts or launching applications at specified times or events. This functionality is managed through the Windows Task Scheduler, a built-in tool that provides a graphical interface, as well as through command-line tools like schtasks.exe and PowerShell cmdlets.

Examples:

  1. Using Task Scheduler GUI:

    To create a scheduled task using the Task Scheduler GUI, follow these steps:

    • Open Task Scheduler by typing "Task Scheduler" in the Windows search bar and pressing Enter.
    • In the Task Scheduler window, click on "Create Basic Task" in the Actions pane.
    • Follow the wizard to name your task, specify the trigger (e.g., daily, weekly, at startup), and define the action (e.g., start a program, send an email).
    • Finish the wizard to create the task.
  2. Using Command Line with schtasks.exe:

    The schtasks.exe command allows you to create, delete, and manage scheduled tasks directly from the command line. Here's how to create a simple task that runs a script daily:

    schtasks /create /tn "DailyScript" /tr "C:\Path\To\YourScript.bat" /sc daily /st 09:00
    • /tn: Task name.
    • /tr: Task run path (script or program to execute).
    • /sc: Schedule type (e.g., daily, weekly).
    • /st: Start time.
  3. Using PowerShell:

    PowerShell provides a more flexible way to manage scheduled tasks with the New-ScheduledTask and Register-ScheduledTask cmdlets. Here's an example of creating a scheduled task with PowerShell:

    $action = New-ScheduledTaskAction -Execute "C:\Path\To\YourScript.ps1"
    $trigger = New-ScheduledTaskTrigger -Daily -At 9AM
    Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DailyScript" -Description "Runs a PowerShell script daily at 9 AM"
    • New-ScheduledTaskAction: Defines the action to perform.
    • New-ScheduledTaskTrigger: Defines the trigger for the task.
    • Register-ScheduledTask: Registers the task with Task Scheduler.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.