gpt4 book ai didi

vbscript - schtasks 参数禁用 "execute when user logged on"

转载 作者:行者123 更新时间:2023-12-04 02:41:06 25 4
gpt4 key购买 nike

我正在尝试在以管理员身份执行的 VBScript 中设置计划任务。如我所见,此脚本设置任务没有问题,但它不会执行,因为它是使用参数仅在用户登录时运行创建的。

代码如下:

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

我在 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.

您的命令行创建应该看起来像这样:

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 "

关于vbscript - schtasks 参数禁用 "execute when user logged on",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19909960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com