gpt4 book ai didi

powershell - 在 Windows 任务计划程序中运行 Powershell 脚本(Windows 7)

转载 作者:行者123 更新时间:2023-12-02 23:46:56 28 4
gpt4 key购买 nike

嗨,我有一个脚本,正在尝试在任务计划程序中启动它。

这给我带来了两个问题。


  • 是该脚本将激活一个需要运行并显示 GUI 的应用程序。那么如何让任务计划程序在特定时间自动登录到 Windows。计算机永远不会/很少被关闭或重新启动。

  • 2.
    我还没有从任务计划程序成功启动 Powershell 脚本。我试过以下:
    powershell.exe -noexit -executionpolicy bypass -command &'Y:\Run Test\StartPowershellScript.ps1'


     powershell.exe -noexit -ExecutionPolicy Bypass -File 'Y:\Run Test\StartPowershellScript.ps1'

    以及上述的变体。
    powershell.exe -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'

    我已经尝试了一些有和没有 &""&'' & 等等的变化。

    现在我不确定它是否可以完成。但我希望我能在这里得到一些帮助。

    编辑 1.
    我刚刚尝试了以下。
    powershell -noexit -ExecutionPolicy Bypass &'Y:\Run Test\StartPowershellScript.ps1'

    在我在PowerShell中这样做之后。
    set-executionpolicy -scope Process -executionPolicy Unrestricted -force
    set-executionpolicy -scope CurrentUser -executionPolicy Unrestricted -force
    set-executionpolicy -scope LocalMachine -executionPolicy Unrestricted -force

    但是,如何确保计算机重新启动后这种情况仍然存在?

    编辑 2。
    看来我无法让计划任务登录或解锁计算机,是否无论如何设置一个任务以在特定时间运行以登录计算机以便计划任务此时可以运行?

    最佳答案

  • 您无法使用计划任务登录 GUI。启用 automatic logon如果您需要交互式桌面。
  • 删除 -NoExit从参数列表中删除,否则 PowerShell 将在脚本完成后继续运行。还要用双引号替换你的单引号。

  • 执行策略是持久的,除非它被本地或组策略取代(在这种情况下 Set-ExecutionPolicy 应该抛出错误)或者您使用临时配置文件登录。

    如果这没有帮助,您需要提供更多详细信息。任务根本就没有开始吗?你有错误吗?任务历史和事件日志说什么? Get-ExecutionPolicy 的输出是什么?

    关于powershell - 在 Windows 任务计划程序中运行 Powershell 脚本(Windows 7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18330523/

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