Como selecionar usando script no Agendador de Tarefas a "execução com privilégios mais altos"

Como selecionar usando script no Agendador de Tarefas a "execução com privilégios mais altos"

Olá, estou fazendo alguns scripts para adicionar uma tarefa em um Agendador de tarefas. Porém preciso ter um script para selecionar "executar com privilégios mais altos".

Código de amostra:

Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False

Responder1

Você pode fazer isso com o -RunLevel Highestsinalizador New-ScheduledTaskPrincipalno PowerShell.

Exemplo:

# Set the scheduled task time and repitition
$TaskTime = New-ScheduledTaskTrigger -Daily -At 12:00

# Set  the task to run as a local administrator with highest level privileges
$TaskUser = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest

# Set actions the schedule task should perform
$Action1 = New-ScheduledTaskAction -Execute "chrome.exe"
$Action2 = New-ScheduledTaskAction -Execute "notepad.exe"

# Registers the task with Task Scheduler
Register-ScheduledTask "Test Scheduled Task" -Action $Action1,$Action2 -Principal $TaskUser

Documentação do PowerShell ScheduledTask.

informação relacionada