使用PowerShell更改远程计算机的鼠标位置?

时间:2015-03-01 01:06:37

标签: powershell powershell-v3.0 invoke-command

我正在编写一个脚本来更改远程计算机鼠标的位置。一台或多台计算机将位于同一LAN上,并且每个GPO都启用了远程PS会话/命令。

我让它在我的计算机上运行,​​但是当我尝试远程运行它时,它不会移动鼠标。

    Invoke-Command -computername remote computer -ScriptBlock
{
while($true)
{
$rand = Get-Random -Maximum 5 -Minimum -5
   $a = [windows.forms.cursor]::Position.y + $rand
   $b = [windows.forms.cursor]::Position.x + $rand

   [Windows.Forms.Cursor]::Position = "$b, $a"

  Start-sleep -s .5

   $rand = Get-Random -Maximum 5 -Minimum -5
   $a = [windows.forms.cursor]::Position.y - $rand
   $b = [windows.forms.cursor]::Position.x - $rand

  [Windows.Forms.Cursor]::Position = "$b, $a"

   Start-sleep -s .5
}
}

我觉得它可能与system.windows.forms程序集有关,但我不确定是否有解决方案。

1 个答案:

答案 0 :(得分:0)

在远程会话中,这是不可能的,因为您的会话没有GUI /句柄来操作。

在主机上运行的本地计算机上,您有一个GUI和句柄,因此可以调用System.Windows.Forms / Cursor。

如果你真的想这样做,你可以把它包装成一个脚本并用一个允许你与桌面交互的工具来执行它。

看看PSExec - 使用" -i"交互式参数。

https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx