操作桌面元素的 Powershell 脚本不适用于 Scheduler

标签 powershell windows-7 scheduled-tasks

当我手动启动它们时,我有 2 个脚本正在运行。

将鼠标光标移出屏幕:

[system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(1999,100)

如果打开了带有标题 HUD 的 Chrome 浏览器,请将其设置为 kiosk 模式:

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")             
[Microsoft.VisualBasic.Interaction]::AppActivate("Hud - Google Chrome")
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")     
[System.Windows.Forms.SendKeys]::SendWait("{F11}")

如果我将它们放入 Windows 7 上的计划任务中,它们将不起作用。

如果我启动一个调用脚本文件的批处理文件,它们就会起作用

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -command "&C:\Users\Miniuser\Documents\chromeHUD.ps1"

但如果我在计划任务中启动批处理文件,则不会。

似乎在计划任务中我无法访问我的 UI 元素。

有什么想法吗?

最佳答案

当脚本作为计划任务运行时,它在不同的上下文/ session 中运行,并且没有它可以“看到”的 GUI,也没有任何方式与现有 session 交互。

关于操作桌面元素的 Powershell 脚本不适用于 Scheduler,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12721014/

相关文章:

powershell - Foreach管道返回类型

haskell - 将 Leksah 调试器与使用 readLn 和类似程序的程序一起使用

javascript - 使用 Node-schedule 安排作业

Heroku 预定作业返回 'command not found' 但使用耙子

powershell - 在 Powershell 中展平嵌套数组

powershell - 特定命令的自定义 PowerShell 选项卡完成?

testing - Windows 8 上的浏览​​器测试?

ruby-on-rails - 为什么我通过 cron 运行的 rake 任务会被调用两次?

powershell - 使用 powershell cmdlet 的 Azure 网站自动化

python - Google App Engine 不会在编辑时更新内容