Score:0

How to select using script on Task Scheduler the "run with highest privileges"

ua flag

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
Josh Zhang avatar
ph flag
Is there a reason you're using `vbscript` instead of the `schtasks.exe` or `PowerShell`?
John Christopher Asajar avatar
ua flag
Nothing, I just started usung vbscript
John Christopher Asajar avatar
ua flag
@JoshZhang is it possible in vbscript?
Josh Zhang avatar
ph flag
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.
John Christopher Asajar avatar
ua flag
@JoshZhang can you give me a sample of it on powershell?
Score:1
ph flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.