问题描述
当我使用 GUI 任务计划程序时,我可以轻松地选中以最高权限运行"复选框.
When I use the GUI Task Scheduler, I can easily check the "Run with highest privileges" checkbox.
不过,我在 VBScript 命令行中也没有发现这样的选项.
I found no such option in the VBScript command line too, however.
有没有办法从 VBScript 中做到这一点?
Is there a way to do that from the VBScript?
这个脚本怎么添加这两个功能?
How to add this script this two feature?
示例 VBScript:http://msdn.microsoft.com/en-us/library/aa383665%28v%3DVS.85%29.aspx
Example VBScript: http://msdn.microsoft.com/en-us/library/aa383665%28v%3DVS.85%29.aspx
权限:http://msdn.microsoft.com/en-us/library/windows/desktop/aa382076%28v=vs.85%29.aspx
推荐答案
此 VBScript 代码自动执行 SchTasks.exe 程序,并应演示您想要执行的操作.要获取使用 SchTasks 创建任务的开关列表,您可以运行以下命令:
This VBScript code automates the SchTasks.exe program and should demonstrate what you want to do. To get a list of the switches for creating tasks with SchTasks, you can run this:
schtasks.exe /create /?
您仍然必须从管理命令提示符运行以下脚本才能创建具有最高"权限的任务.此外,如果您希望使用系统帐户以外的帐户,则应使用/RP 开关.如果您完全自动化,您可能还希望使用/F 开关来强制覆盖现有任务.否则它可能会在等待用户输入时挂起.
You still have to run the below script from an administrative command-prompt to be able to create a task with "Highest" privileges. Also, if you wish to use an account other than the system account, you should use the /RP switch. If you're fully automating it, you may wish to use the /F switch as well to force overwriting an existing task. Otherwise it may hang while waiting for user input.
Option Explicit
Dim WshShell, strWinDir, strCmdLine, lngExitCode
Const OpenAsCurrentWindowIsOpened = 10, WaitForExit = True
Set WshShell = CreateObject("WScript.Shell")
strWinDir = WshShell.ExpandEnvironmentStrings("%WINDIR%")
strCmdLine = strWinDir & "\System32\SCHTASKS.exe /create /SC DAILY /TN ""My VBScript Task"" /TR """ & strWinDir & "\System32\calc.exe"" /RL HIGHEST /RU ""NT AUTHORITY\SYSTEM"""
lngExitCode = WshShell.Run(strCmdLine, OpenAsCurrentWindowIsOpened, WaitForExit)
If lngExitCode = 0 Then
WScript.Echo "Success"
Else
WScript.Echo "Failed with error code " & CStr(lngExitCode)
End If
这篇关于如何在 VBScript 中指定“以最高权限运行"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!