如何在任務計劃程序上使用腳本選擇“以最高權限運行”

如何在任務計劃程序上使用腳本選擇“以最高權限運行”

您好,我正在編寫一些腳本來在任務計劃程式上新增任務。但是我需要一個腳本來選擇“以最高權限運行”。

範例程式碼:

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

答案1

您可以使用PowerShell 中的-RunLevel Highestfor 標誌來完成此操作。New-ScheduledTaskPrincipal

例子:

# 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 排程任務文檔

相關內容