You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10任务计划程序第二Action无法运行PS1脚本求助

Troubleshooting Task Scheduler Error 2147943726 on Windows 10 for Secondary PowerShell Action

Let’s break down this issue first: error code 2147943726 translates to ERROR_PRIVILEGE_NOT_HELD—meaning your task’s second action isn’t getting the necessary permissions to run, even though you’re using a domain admin account. The difference between Windows 10 and Server 2012 comes down to stricter UAC (User Account Control) defaults and task context handling on client OSes. Here are actionable fixes to resolve this:

1. Enforce Elevated Permissions for the Entire Task

Windows 10’s task scheduler is pickier about permission inheritance across actions compared to Server 2012. Even if your first action runs fine, the second might drop elevated rights. Fix this by:

  • Opening the task’s properties, navigating to the General tab.
  • Ensuring "Run whether user is logged on or not" is checked.
  • Checking Run with highest privileges—this forces both actions to run in a fully elevated context, bypassing UAC restrictions that might block the PowerShell script in the second step.

2. Adjust File/Directory Permissions

Your script and log file are stored in C:\Program Files (x86)\AIM Tasks\, a protected system directory. Windows 10’s default permissions here might prevent the task’s secondary action from accessing the file, even with an admin account. Try:

  • Moving the script and log file to a non-protected directory like C:\AIM Tasks\ (create this folder if it doesn’t exist).
  • If you keep them in the original location, right-click the AIM Tasks folder, go to Properties > Security > Edit, add Domain\Administrator, and grant Full Control permissions.

3. Modify the PowerShell Action’s Command Line

Using -File in the PowerShell arguments can sometimes cause context issues in secondary task actions. Switch to -Command to ensure proper script execution:
Change your action’s arguments from:

-NoProfile -ExecutionPolicy Bypass -file "C:\Program Files (x86)\AIM Tasks\EmailNightlyBilling.ps1"

To:

-NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Program Files (x86)\AIM Tasks\EmailNightlyBilling.ps1'"

This syntax explicitly invokes the script in a new execution context, which can resolve permission-related path parsing issues.

4. Verify First Action Completion & Context

Make sure your first billing program action is fully exiting before the second action runs:

  • Go to the task’s Settings tab, set "If the task is already running, then the following rule applies" to "Do not start a new instance".
  • Ensure the first action returns an exit code of 0 (success) so the task knows to proceed. You can confirm this by checking the task’s history log after a run.
  • If the first action runs as a non-elevated process, Windows 10 might not elevate the second action automatically—hence why forcing "Run with highest privileges" (from step 1) is critical.

5. Add Debug Logging to Your PowerShell Script

To pinpoint exactly where the script fails when run as the second action, add transcript logging to capture errors:
Add these lines at the start of EmailNightlyBilling.ps1:

Start-Transcript -Path "C:\AIM Tasks\PS_Email_Script_Log.txt" -Append
$ErrorActionPreference = "Stop"

And this at the end:

Stop-Transcript

Run the task again, then check the log file—this will show if the script fails at loading the attachment, connecting to SMTP, or another step, confirming whether it’s a permission or resource issue.


内容的提问来源于stack exchange,提问作者Jim Wilcox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:40:02