如果我在AWS服务器上运行窗口自动化应用程序,那么SendInput或SendKeys方法就无法工作。当我在AWS窗口上调用WPF应用程序中的SendInput和Sendkey方法时,下面的消息是接收错误消息。
System.Exception: Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.
location: WindowsInput.WindowsInputMessageDispatcher.DispatchInput(INPUT[] inputs)
location: WindowsInput.MouseSimulator.MoveMouseTo(Double absoluteX, Double absoluteY)在没有RDP会话的情况下运行my自动化应用程序时。它会崩溃。我想,这是相关的RDP会议。如果我正在连接RDP会话,我的应用程序运行得很好。
发布于 2020-07-15 01:37:49
您应该提供比"RDP会话“更多的信息。
您使用的是本机函数,SendInput。
[DllImport("user32.dll", SetLastError = true)]
public static extern UInt32 SendInput(UInt32 numberOfInputs, INPUT[] inputs, Int32 sizeOfInputStructure);根据微软的文件,
该函数返回成功插入键盘或鼠标输入流的事件数。如果函数返回零,则输入已被另一个线程阻塞。要获得扩展的错误信息,请调用
GetLastError。当UIPI阻止此函数时,它将失败。请注意,GetLastError和返回值都不会指示故障是由UIPI阻塞引起的。
请提供GetLastError结果。
当函数的返回值指示这样的调用将返回有用的数据时,您应该立即调用GetLastError函数。
public void DispatchInput(INPUT[] inputs)
{
if (inputs == null) throw new ArgumentNullException("inputs");
if (inputs.Length == 0) throw new ArgumentException("The input array was empty", "inputs");
try
{
var successful = NativeMethods.SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof (INPUT)));
}
catch
{
// if you execute any function that communicate with OS before here, LastError might be lost.
error = Marshal.GetLastWin32Error();
Console.WriteLine("The last Win32 Error was: " + error);
}
if (successful != inputs.Length)
throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.");
}https://stackoverflow.com/questions/62906186
复制相似问题