News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Problem with Service Message Boxes

Started by Astro, April 26, 2010, 09:47:02 AM

Previous topic - Next topic

Astro

Hi,

I can't figure out what is going on here. Maybe I've screwed the message display options up in the latest build.

My client is testing a piece of software that should display a message box at service start-up. He tells me that he recently did a Windows update, and that since doing this, my previously working code now doesn't work.

I know it was working as I had it working on my dev computer here. I'm currently messing around installing Win 7 here to test.

The message box code:

First message:
push MB_ICONINFORMATION or MB_SERVICE_NOTIFICATION
lea eax,App
push eax
lea eax,Msg1
push eax
push 0
call MessageBox


Second message:
push MB_ICONINFORMATION or MB_SERVICE_NOTIFICATION or MB_SYSTEMMODAL
lea eax,App
push eax
lea eax,Msg2
push eax
push 0
call MessageBox


It appears the rest of the service code is working fine, except this.

Anyone else written Windows service code with message boxes that work, or did work on Windows 7?

As far as I can tell there is nothing wrong with this code, and the SCM is reporting the service as started. The service appears to respond correctly to start/stop requests from the SCM. I'm not sure the status of UAC, or whether it is a factor. Does it hijack the desktop so service messages won't display?

Best regards,
Robin.

Slugsnack

correct me if i'm wrong, but is it not bad practice to call usermode apis from a service/driver ? you should be using debug prints with functions like DbgPrint()/KdPrint()

Astro

Quote from: Slugsnack on April 26, 2010, 10:00:18 AM
correct me if i'm wrong, but is it not bad practice to call usermode apis from a service/driver ? you should be using debug prints with functions like DbgPrint()/KdPrint()
Is it? I thought the point of service code was to run in Ring 3? At least, that is the latest doctrine from MS, in order to avoid writing kernel mode code for purposes better suited to usermode.

Their usermode APIs have this service flag, which they claim is valid on Windows 7. It works fine on XP; Win 7 is doing something to the desktop that prevents the dialog appearing.

http://msdn.microsoft.com/en-us/library/ms645505%28VS.85%29.aspx

QuoteMB_SERVICE_NOTIFICATION

     The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.

    Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token.

    If this flag is set, the hWnd parameter must be NULL. This is so that the message box can appear on a desktop other than the desktop corresponding to the hWnd.

    For information on security considerations in regard to using this flag, see Interactive Services. In particular, be aware that this flag can produce interactive content on a locked desktop and should therefore be used for only a very limited set of scenarios, such as resource exhaustion.

Best regards,
Robin.

Slugsnack

http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx

QuoteImportant  Services cannot directly interact with a user as of Windows Vista. Therefore, the techniques mentioned in the section titled Using an Interactive Service should not be used in new code.

Interacting with a User from a Service Indirectly

You can use the following techniques to interact with the user from a service on all supported versions of Windows:

Display a dialog box in the user's session using the WTSSendMessage function.
Create a separate hidden GUI application and use the CreateProcessAsUser function to run the application within the context of the interactive user. Design the GUI application to communicate with the service through some method of interprocess communication (IPC), for example, named pipes. The service communicates with the GUI application to tell it when to display the GUI. The application communicates the results of the user interaction back to the service so that the service can take the appropriate action. Note that IPC can expose your service interfaces over the network unless you use an appropriate access control list (ACL).
If this service runs on a multiuser system, add the application to the following key so that it is run in each session: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. If the application uses named pipes for IPC, the server can distinguish between multiple user processes by giving each pipe a unique name based on the session ID.

The following technique is also available for Windows Server 2003, Windows XP, and Windows 2000:

Display a message box by calling the MessageBox function with MB_SERVICE_NOTIFICATION. This is recommended for displaying simple status messages. Do not call MessageBox during service initialization or from the HandlerEx routine, unless you call it from a separate thread, so that you return to the SCM in a timely manner.

In the same page you linked me to, scroll further down to see :
QuoteMB_SERVICE_NOTIFICATION is ignored on Vista
Note: Starting with Vista, the desktop is isolated from services via session separation. If a service calls MessageBox with MB_SERVICE_NOTIFICATION the message box will not be displayed. Instead USER32 will intercept the call and immediately return a fake successful result code to simulate a button press. (I don't remember the exact return code - probably IDOK or IDCANCEL.)

Astro

 :red :red

I've tested it and it is intercepted and re-directed to the system log.

MS should put a big note in red that MessageBox does not work this way on Vista/7. Would save a lot of hassle.

Best regards,
Robin.