gpt4 book ai didi

c# - 远程调用时 Powershell SendKeys 访问被拒绝

转载 作者:行者123 更新时间:2023-11-30 23:14:08 27 4
gpt4 key购买 nike

我正在测试一个监听远程机器按键的程序,所以我需要以某种方式生成它们,最好只使用 powershell 核心。

当我尝试通过调用命令在远程计算机上使用 SendKeys 时,我遇到访问被拒绝(win32 异常或 dotnetmethod 异常),即使凭据已提供给具有管理员权限的脚本并且它在本地运行良好。

我以这种方式运行了很多脚本,而这个脚本是唯一失败的脚本(并且它在所有操作系统上都以相同的方式失败)

例如

$script =
{
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait($item);
}

invoke-command -computername $machine -scriptblock $script -credential $cred

SendInput 看起来可能是一个很有前途的替代品,但我一直无法找到适合我的示例。

最佳答案

原来问题是由于无法访问 Windows 用户 session 。

我通过在远程机器上创建计划任务并调用 powershell 脚本来解决这个问题。这样脚本就可以在用户 session 中运行。

否则它似乎在无法调用键盘和鼠标 API 的无图形用户界面 session 中运行。

关于c# - 远程调用时 Powershell SendKeys 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43307722/

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