首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在AWS窗口服务器中运行windows自动化应用程序

如何在AWS窗口服务器中运行windows自动化应用程序
EN

Stack Overflow用户
提问于 2020-07-15 01:18:48
回答 1查看 194关注 0票数 0

如果我在AWS服务器上运行窗口自动化应用程序,那么SendInputSendKeys方法就无法工作。当我在AWS窗口上调用WPF应用程序中的SendInput和Sendkey方法时,下面的消息是接收错误消息。

代码语言:javascript
复制
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会话,我的应用程序运行得很好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-15 01:37:49

您应该提供比"RDP会话“更多的信息。

您使用的是本机函数,SendInput

代码语言:javascript
复制
[DllImport("user32.dll", SetLastError = true)]
public static extern UInt32 SendInput(UInt32 numberOfInputs, INPUT[] inputs, Int32 sizeOfInputStructure);

根据微软的文件,

该函数返回成功插入键盘或鼠标输入流的事件数。如果函数返回零,则输入已被另一个线程阻塞。要获得扩展的错误信息,请调用GetLastError。当UIPI阻止此函数时,它将失败。请注意,GetLastError和返回值都不会指示故障是由UIPI阻塞引起的。

请提供GetLastError结果。

当函数的返回值指示这样的调用将返回有用的数据时,您应该立即调用GetLastError函数。

代码语言:javascript
复制
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.");
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62906186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档