0

Hi I'm doing some scripting to add a task on a Task Scheduler. However I need to have a script to select the "run with highest privileges".

Sample code:

Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972

1 Answers1

1

You can accomplish this with the -RunLevel Highest flag for New-ScheduledTaskPrincipal in PowerShell.

Example:

# 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

PowerShell ScheduledTask documentation.

Josh Zhang
  • 159
  • 9