WTSSendMessage (wtsapi32)
Last changed: anonymousrandom-174.172.243.117

.
Summary
The WTSSendMessage function displays a message box on the client desktop of a specified Terminal Services session.

C# Signature:

[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)] ref int pResponse,
            bool bWait);

VB Signature:

Declare Function WTSSendMessage Lib "wtsapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

    // Useful constants
    public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
    public static int WTS_CURRENT_SESSION = -1;

Tips & Tricks:

Please add some!

Sample Code:

    public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
    public static int WTS_CURRENT_SESSION = -1;

    bool result = false;
    String title = "Hello";
    int tlen = title.Length;
    String msg = "Terminal Service!";
    int mlen = msg.Length;
    int resp = 0;
    result = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, title,     tlen, msg, mlen, 0, 0, ref resp, false);
    int err = Marshal.GetLastWin32Error();
    System.Console.WriteLine("result:{0}, errorCode:{1}, response:{2}", result, err, resp);

Alternative Managed API:

Do you know one? Please contribute it!

Documentation