Click here to Skip to main content
15,907,233 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Developers,

I am able show the message box in Windows service but it is showing center of the screen. I want to display in Right side of below corner of screen.Below is the my code please help me this.

Thanks & Regards,
Aravind G


CODE:

C#
public static IntPtr WTS_CURRENT_SERVER_HANDLE = IntPtr.Zero;
        public static int WTS_CURRENT_SESSION = 1;


        [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);


        bool result = false;
                   String title = "Alert";
                   int tlen = title.Length;
                   String msg = sb.ToString();
                   int mlen = msg.Length;
                   int resp = 4;
                   result = WTSSendMessage(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, title, tlen, msg, mlen, 0, 3, out resp, true);
                   int err = Marshal.GetLastWin32Error();
Posted
Updated 1-Jan-14 2:52am
v2

1 solution

There are two ways to display messages directly from windows service.
WTSSendMessage - the one you using here does not enable to position of the message box (there are no params for that).
Allow service to interact with desktop - you can check this on the LogOn tab of your service. When it's on you can use standard windows message box to display messages, and position it. However! as long as the message box is on the service is on hold!

You may also consider to write some helper application that talks to the service behind the curtains and shows message boxes for him...
 
Share this answer
 
Comments
Aravind Garre 1-Jan-14 9:17am    
Thank you for suggesting this. kornfeld Eliyahu peter
Kornfeld Eliyahu Peter 1-Jan-14 9:23am    
You welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900