简体   繁体   English

如何在 PowerShell 中无论用户是否登录都安排任务?

[英]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 中完成,是否可以用另一种脚本语言来完成?

You'll need to specify a user (like /RU system ), but it should be the default whether to run logged in or not.您需要指定一个用户(如/RU system ),但无论是否登录运行,它都应该是默认设置。 You can look at this link for a list of all schtasks.exe parameters.您可以查看此链接以获取所有schtasks.exe参数的列表。

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.

相关问题 使用PowerShell使用“运行是否用户已登录”选项来安排任务创建 - Schedule task creation with option “”Run whether user is logged in or not“” using powershell 如何Powershell任务管理器的脚本“无论用户是否登录都运行” - How to Powershell a script for Task Manager to "run whether a user is logged on or not" Powershell:将计划任务设置为在用户未登录时运行 - Powershell: Set a Scheduled Task to run when user isn't logged in 如何在PowerShell中获取登录用户的电子邮件 - How to obtain email of the logged in user in powershell 我如何使用powershell和schedule.service运行计划的任务 - How I could run a scheduled task with powershell and schedule.service 如何使用计划任务执行powershell(x86)? - How to execute powershell(x86) with schedule task? 在Powershell中获取登录用户 - Getting the logged in user in Powershell 如何使用 PowerShell 在系统重新启动后延迟 10 分钟在 Windows 任务调度程序中调度任务? - How to schedule a task in Windows Task Scheduler with delay of 10 minutes after system restarted using PowerShell? Powershell任务计划中的日期格式错误 - Error with date format at Task Schedule from Powershell 我对 Powershell 和任务计划有疑问 - I have a issue with Powershell and task schedule
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM