[英]How to schedule a task wether the user is logged on or not in PowerShell?
I have a problem regarding how to make a scheduled task to run whether the user is logged on or not.我有一个关于如何使计划任务运行的问题,无论用户是否登录。 It must be done in PowerShell. What I have done is:必须在PowerShell完成。我所做的是:
$WINDIR/system32/schtasks.exe /create /tn TaskName /sc daily /st 15:05:00 /tr "C:\cygwin\opt\IBM\tpchc\bin\tools\TheFileToRun.bat"
But can I provide an extra argument making this task run no matter if the user is logged on or off?但是我可以提供一个额外的参数来使这个任务无论用户是登录还是注销都运行吗?
If it cant be done in PowerShell is it then possible to do it in another script language?如果不能在 PowerShell 中完成,是否可以用另一种脚本语言来完成?
if you add如果你添加
/RU <username> /RP <password>
to the call to schtasks.exe you will get "Run whether user is logged on or not" selected.到对 schtasks.exe 的调用,您将选择“无论用户是否登录都运行”。
You can also use the /NP
instead, which will also give you "Run whether user is logged on or not", but also "Do not store password..." which will limit the accessible resources.您也可以改用/NP
,这也会为您提供“无论用户是否登录都运行”,以及“不存储密码...”,这将限制可访问的资源。
I got a Working solution, just add this:我有一个可行的解决方案,只需添加以下内容:
/RU "NT AUTHORITY\SYSTEM" /RP *
Will run as System and ignore password, Tested on XP将作为系统运行并忽略密码,在 XP 上测试
If you're using common account:如果您使用的是普通帐户:
/RU {accountName} /RP {password}
If you're using gMSA account:如果您使用的是 gMSA 帐户:
/RU {accountName}$ /RP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.