dav*_*lla 4 vbscript windows-task-scheduler
我正在尝试在以管理员身份执行的 VBScript 中设置计划任务。正如我所看到的,该脚本设置任务没有问题,但它不会执行,因为它是使用参数创建的run only when user is logged on。
代码如下:
Set objShell=Wscript.CreateObject("Wscript.Shell")
command= windir&"\system32\schtasks.exe /create /sc minute /mo "&minutes&" /tn "&APPNAME&" /f /tr ""C:\Windows\System32\wscript.exe '"&getAplicationPath&"\"&wscript.ScriptName&"' cron "
objShell.Run command,0, false
Run Code Online (Sandbox Code Playgroud)
我无法在 msdn.microsoft.com 或 Google 搜索中找到必须设置以禁用该选项的参数。
如果您希望任务在没有用户登录的情况下运行,则需要提供任务运行的用户。为此,您需要选项/RU(针对运行帐户)和/RP(针对其密码)。如果任务只需要访问本地资源,您可以使用该选项来阻止存储密码/NP(不过,您仍然需要在创建任务时提供一次密码)。我认为后一个选项在 Vista 之前的 Windows 版本上不可用。
引用以下输出中的相关部分schtasks /create /?:
/RU username Specifies the "run as" user account (user context)
under which the task runs. For the system account,
valid values are "", "NT AUTHORITY\SYSTEM"
or "SYSTEM".
For v2 tasks, "NT AUTHORITY\LOCALSERVICE" and
"NT AUTHORITY\NETWORKSERVICE" are also available as well
as the well known SIDs for all three.
/RP [password] Specifies the password for the "run as" user.
To prompt for the password, the value must be either
"*" or none. This password is ignored for the
system account. Must be combined with either /RU or
/XML switch.
/NP No password is stored. The task runs non-interactively
as the given user. Only local resources are available.
Run Code Online (Sandbox Code Playgroud)
您的命令行创建可能看起来像这样:
command= "%windir%\system32\schtasks.exe /create" & _
" /sc minute /mo " & minutes & " /tn " & APPNAME & _
" /ru " & username & " /rp " & password & _
" /f /tr ""C:\Windows\System32\wscript.exe '" & _
getAplicationPath & "\" & wscript.ScriptName & "' cron "
Run Code Online (Sandbox Code Playgroud)