问题
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