Windows Services Popup MessageBox dialog box
Since Windows upgraded to Vista version, the system service is not allowed to pop up those extremely brutal messagebox (as for why not to let pop-up, the principle is a little complicated, I am not very clear, just a little bit, here is not embarrassing, self-Google bar), However, no matter how wonderful, there is always the need to eject the MessageBox from the service, so see the relevant cheats at home and abroad, there is a way to help us pop up this dialogue, the following is the implementation of the code (the specific meaning of internal functions MSDN detailed understanding).
#include <windows.h>
#include <WtsApi32.h>
#pragma comment (lib, "WtsApi32.lib")
BOOL Svcmessagebox (LPSTR lpcap, LPSTR lpmsg, DWORD style, DWORD &result)
{
if (NULL = = Lpmsg | | NULL = = Lpcap)
return FALSE;
result = 0;
DWORD Sessionxid = Wtsgetactiveconsolesessionid ();
Return Wtssendmessage (Wts_current_server_handle, Sessionxid,
Lpcap, strlen (Lpcap),
Lpmsg, strlen (lpmsg),
Style, 0, &result, FALSE);
}
When compiling the code, maybe vs will prompt you not to find the Wtsgetactiveconsolesessionid () function, because the function is supported from the version of Windows XP, so there is no such function on the old version system. And your project is to upgrade from the old code, such as the definition of _win32_winnt as 0x0500, the solution is as follows:
#define _WIN32_WINNT 0x0501
About these hexadecimal represents the specific meaning of your own MSDN bar.
Attention:
Pop-up dialog is the user's current process, so pop-up dialog box does not block the service process, the server can not judge the function's return value to make a decision, this is very awkward, there is no Daniel encountered the problem, please point twos.
At the same time in Windows also saw other services, pop up as shown in the dialog box, feel very cool, than the MessageBox user experience is much better, but do not know how to achieve, kneeling to achieve the method ah.
How can this be achieved?
Windows Services Popup MessageBox dialog box