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
5
  • Is there a reason you're using vbscript instead of the schtasks.exe or PowerShell?
    – Josh Zhang
    Aug 10, 2021 at 1:17
  • Nothing, I just started usung vbscript Aug 10, 2021 at 3:21
  • @JoshZhang is it possible in vbscript? Aug 10, 2021 at 3:26
  • While it's possible to do with vbscript, I can't find the documentation for highest privileges flag, plus it is much easier to accomplish this using PowerShell or even schtasks.exe.
    – Josh Zhang
    Aug 11, 2021 at 20:57
  • @JoshZhang can you give me a sample of it on powershell? Aug 11, 2021 at 23:48

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .