带有取消从任务调度程序调用的用户的选项的自动关闭脚本

问题描述 投票:0回答:0

我正在尝试为我们的办公室工作人员设置一个计划任务,该任务将在预设时间关闭计算机。

我已经有一个在 11:00 硬关闭的脚本,用户没有任何选择。

但是,为了帮助我们的节能系统,我想在晚上早些时候关闭,但让任何迟到的员工可以选择推迟关闭。

当我从 PowerShell 终端运行它时它工作,但是当它在计划任务中时它停止工作。

从计划任务运行的 PowerShell 脚本是否有任何限制?
有没有一种本机方法可以请求用户关闭权限?使用 Bat 文件会更容易吗?

我已经用这样的参数代码设置了计划任务:

$taskAction = New-ScheduledTaskAction `
    -Execute 'powershell.exe' `
    -Argument '\Users\deployment\docs\RequestPowerOff-GUI.ps1'

从 ps1 文件运行的代码是这样的:

Add-Type -AssemblyName PresentationFramework

shutdown -s -t 600 -f

$answer = [System.Windows.MessageBox]::Show( "Computer will Auto Shutdown in 10 min. Would you like to continue working?", "Auto Shutdown ", "YesNo", "Warning" )

if ($answer -eq "Yes")
{
    shutdown -a
    [void] [System.Windows.MessageBox]::Show( "poweroff canceled", "Auto poweroff", "OK", "Information" )
    
} 
windows powershell deployment scheduled-tasks
© www.soinside.com 2019 - 2024. All rights reserved.