Tuesday, 10 September 2013

Display a message using .NET Windows Services on Windows 7

Display a message using .NET Windows Services on Windows 7

I have a issue when display a message using .NET window service on Windows
7.It worked properly on Windows XP.I know that it doesn't work on Windows
7 as explained in Microsoft site and a few forums including
Stackoverflow.I have followed the following example(using WTSSendMessage)
from Pinvoke.NET as mentioned in the Stackoverflow.But it didn't work
either.that example worked on Windows XP properly.Can some one please help
me as this is a really big issue needed to be fixed ASAP since we already
migrated to Windows7.
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)] out int pResponse, bool bWait);
Variable declaration: public static IntPtr WTS_CURRENT_SERVER_HANDLE =
IntPtr.Zero; public static int WTS_CURRENT_SESSION = -1;
Code: 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, out resp, false); int
err = Marshal.GetLastWin32Error(); System.Console.WriteLine("result:{0},
errorCode:{1}, response:{2}", result, err, resp);

No comments:

Post a Comment