如果服务器被锁定 - 是否可以将密钥发送到子客户端窗口?

发布于 2024-12-20 09:30:40 字数 954 浏览 3 评论 0原文

我的程序找到任何子窗口,如果一个由三部分组成的应用程序显示错误框,那么我想关闭它..并且当服务器未锁定时它工作正常。

代码:

[DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool PostMessage(IntPtr hwnd, uint msg, IntPtr WParam, IntPtr lParam);

    [DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool BringWindowToTop(IntPtr hwnd);

public static bool FocusWindowAndSendEnter(IntPtr hWnd)
{
    try
    { // hWnd = pointer to subwindow, like messagebox.

        uint WM_KEYDOWN = 0x0100;

       //Set focus
      var res1 =  BringWindowToTop(hWnd);

        //Send enter_Key 
      var res2 = PostMessage(hWnd, WM_KEYDOWN, (IntPtr)Keys.Enter, IntPtr.Zero);

      return (res1 == res2 == true);

    }
    catch (Exception ex)
    {
        Logger.LogException(MethodInfo.GetCurrentMethod().Name, ex);
    }

    return false;
}

如果服务器被锁定但正在运行,可以这样做吗?

My program, finds any subwindows, the case if an 3-part app shows an Error box, then i want to close it.. and it works fine, when the server not is locked.

Code:

[DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool PostMessage(IntPtr hwnd, uint msg, IntPtr WParam, IntPtr lParam);

    [DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private extern static bool BringWindowToTop(IntPtr hwnd);

public static bool FocusWindowAndSendEnter(IntPtr hWnd)
{
    try
    { // hWnd = pointer to subwindow, like messagebox.

        uint WM_KEYDOWN = 0x0100;

       //Set focus
      var res1 =  BringWindowToTop(hWnd);

        //Send enter_Key 
      var res2 = PostMessage(hWnd, WM_KEYDOWN, (IntPtr)Keys.Enter, IntPtr.Zero);

      return (res1 == res2 == true);

    }
    catch (Exception ex)
    {
        Logger.LogException(MethodInfo.GetCurrentMethod().Name, ex);
    }

    return false;
}

Can this be done if the server is locked, but running?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-12-27 09:30:40

当计算机被锁定时,出于安全目的,您能做的事情非常有限。我怀疑是否有办法解决这个问题,除非您阻止计算机被锁定,或者首先阻止消息框显示。

您试图用错误的方法解决问题。

了解如何处理该错误消息框,并采取措施防止这种情况发生。当电脑被锁定时,不要指望能做很多事情。

When a computer is locked, you are very limited in what you can do - for security purposes. I doubt there is a way around this unless you either stop the computer being locked, or stop the message box from showing up in the first place.

You're attempting to solve a problem in the wrong methods.

Find out what you can about that error message box and do what you can to prevent that happening. Don't expect to have much you can do when the PC is locked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文