Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# wtssendmessage

class Service
{
    [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);
    public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
    public static int WTS_CURRENT_SESSION = 1;
    public void Start()
    {
        for (int user_session = 10; user_session>0; user_session--)
        {
            Thread t = new Thread(() => {
                try
                {                        
                    bool result = false;
                    String title = "Alert";
                    int tlen = title.Length;
                    String msg = "hi";
                    int mlen = msg.Length;
                    int resp = 7;
                    result = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, user_session, title, tlen, msg, mlen, 4, 0, out resp, true);
                    int err = Marshal.GetLastWin32Error();
                    if (err == 0)
                    {
                        if (result) //user responded to box
                        {
                            if (resp == 7) //user clicked no
                            {

                            }
                            else if (resp == 6) //user clicked yes
                            {

                            }
                            Debug.WriteLine("user_session:" + user_session + " err:" + err + " resp:" + resp);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("no such thread exists", ex);
                }
                //Application App = new Application();
                //App.Run(new MessageForm());
            });
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }

    }
    public void Stop()
    {
        // write code here that runs when the Windows Service stops.  
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# supplier equivalent 
Csharp :: small index c# 
Csharp :: convert excel to datatable without xml configuration 
Csharp :: c# get Full Exception message if InnerException is not NULL 
Csharp :: what loops are entry controlled c# 
Csharp :: 110771 
Csharp :: true false when key pressed in c sharp unity 
Csharp :: string extentions not working 
Csharp :: .net core api routing not working 
Csharp :: c# read key without writing 
Csharp :: c# generate random key with specified length 
Csharp :: touch screen to world point 
Csharp :: log4net rollingfileappender c# 
Csharp :: php encrypt message encrypt() decrypt 
Csharp :: c# compare 2 binary files 
Csharp :: c# same folder path 
Csharp :: attribute decorator to require email format of string c# 
Csharp :: Here we create a MigraDoc Document object to draw the content of this page 
Csharp :: get fixedupdate interval unity 
Csharp :: C# Check if variables are equal 
Csharp :: player movement script unity 
Csharp :: convert bool to uint in solidity 
Csharp :: get current culture in controller asp.net core 6 
Csharp :: unity wheelcollider antiroll 
Csharp :: c# result set from stored procedure 
Csharp :: c# nuint 
Csharp :: process which converts natural sugar into alcohol by yeast 
Csharp :: c# mail retrieve library 
Csharp :: c# webclient ssl bypass 
Csharp :: Area Of the triangle with condition 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =