操作桌面元素的 Powershell 脚本不适用于 Scheduler [英] Powershell scripts manipulating desktop elements don't work with Scheduler
问题描述
当我手动启动它们时,我有 2 个脚本在工作.
I have 2 scripts working, when I start them manually.
将鼠标光标移出屏幕:
[system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(1999,100)
如果有一个带有标题 HUD 的 chrome 浏览器打开,请将其置于信息亭模式:
If there is a chrome browser open with title HUD, put it to kiosk mode:
[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 上的计划任务中,它们将不起作用.
If I put them in a Scheduled Task on Windows 7 they don't work.
如果我启动一个调用脚本文件的批处理文件,它们就会工作
They work if I start a batch file calling the script file
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noninteractive -command "&C:\Users\Miniuser\Documents\chromeHUD.ps1"
但如果我在计划任务中启动批处理文件,则不会.
But not if I start the batch file in a Scheduled Task.
似乎在计划任务中我无法访问我的 UI 元素.
It seems in a Scheduled Task I can't acces my UI elements.
有什么想法吗?
推荐答案
作为 alroc 的回答,它确实在另一个上下文/会话下运行.
As alroc answers, it does run under another context/session.
我找不到任何解决方法来解决这个问题......使用纯powershell......但是我能够使用wscript完成工作.
I was not able to find any workaround to get pass this... Using pure powershell... However i was able to get the job done with wscript.
在你的 PS 脚本中,用这个打开你的 chrome
in your PS script, open your chrome with this
(new-object -com wscript.shell).run("http://localhost/",3)
它将以全屏方式打开默认浏览器.我可以将它与任务调度程序中的 sendkeys 一起使用!
It will open the default browser in full screen. i could use this with sendkeys in the task scheduler!
这篇关于操作桌面元素的 Powershell 脚本不适用于 Scheduler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!