WTSSendMessage don't show messagebox on remote desktop

早过忘川 提交于 2020-02-25 13:41:27

问题


I have a Windows service application that displays a confirm popup for further action. It works fine when I install the service application on my local machine, but when I install it on the remote machine, the confirm popup is not getting displayed.

[DllImport("Kernel32.dll", SetLastError = true)]
static extern int WTSGetActiveConsoleSessionId();
public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;

public static int ConfirmPopup(string message, string title)
{
    try
    {
        WTSSendMessage(WTS_CURRENT_SERVER_HANDLE,
            WTSGetActiveConsoleSessionId(), title, title.Length, message,
            message.Length, 3, 0, out int response, true);

        return response;
    }
    catch (Exception ex)
    {
        Trace.WriteLine($"Exception:ConfirmPopup()::{ex.Message}");
        return 0;
    }
}

[DllImport("wtsapi32.dll", SetLastError = true)]
static extern bool WTSSendMessage(
    IntPtr hServer,
    [MarshalAs(UnmanagedType.I4)] int SessionId,
    String pTitle,
    [MarshalAs(UnmanagedType.U4)] int TitleLength,
    String pMessage,
    [MarshalAs(UnmanagedType.U4)] int MessageLength,
    [MarshalAs(UnmanagedType.U4)] int Style,
    [MarshalAs(UnmanagedType.U4)] int Timeout,
    [MarshalAs(UnmanagedType.U4)] out int pResponse,
    bool bWait);

We have to show a demo to the client on a remote machine and it's not working there. It's working fine on the local machine.

来源:https://stackoverflow.com/questions/56528614/wtssendmessage-dont-show-messagebox-on-remote-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!