views:

149

answers:

4

This is a coding question. Please read it before you flag it as belonging on ServerFault as the last one I wrote got thrown over there in less than 5 minutes.

I'm testing my win32/c++ application on XP which has the latest service packs. It contains two administrative user accounts both without passwords. I log in as User1 and start my app. The app runs, its main window appears and all is well with the world. I then log User1 off without first closing my app. Yes, I used "log off" not "switch user"

I then log in as User2 and my application is still running. I see it on the User 2 desktop, and I can even interact with it. It appears to be functioning normally. And task manager shows it running as User1.

Any ideas which might be going on here? Other applications (like notepad) don't exhibit this issue, yet mine does. Seems to me I'm doing something wrong in my code, but it really is a rather standard win32/c++ app. Perhaps I'm not processing some shutdown message properly? I'm sorry I can't give more specifics right now. I'm really hoping for some clue to spark further research.

A: 

How exactly are you starting the app?

Does the app do anything fancy with window stations or desktops?

Are there any other processes running as User1 after you log off?

SLaks
+1  A: 

Are you sure your application isn't running as a service? A service with "Interact with Desktop" could look like this.

UPDATE: It must be somehow related to a service. A normal application, running in a session will be forced to close by Windows before the logoff is complete. Even if you don't handle the end session messages, Windows will tell the user about the nonresponding process and/or just kill it.

Murray
Nope. Not a service. But it does some local RPC with a running service.
Charles
A: 

Do you need to be listening for a shutdown or logoff events?

Check out this answer for a similar question.

That answer refers to listening for WM_QUERYENDSESSION.

See WM_QUERYENDSESSION Message

Jesse
You only need to listen for that if you intend to deal with those exits differently. Otherwise DefaultWindowProc(WM_QUERYENDSESSION) will send/post? you a WM_QUIT.
MSalters
+1  A: 

Check windows task manager's for 2 things:

  1. "Session ID" column
  2. "User Name" column

If either of these columns do not show up then select them from View -> Select columns.

Check which username and session your application that is staying open with is on. Then go and start notepad.exe and compare to the session ID and User Name that it is started with.

When you do a logoff it will close the applications running under your Session ID and username.

I'm guessing that your application is running in it's own session ID and/or username.

When you login with the other user it checks to see if it can re-use a session that is already started for the new username. So that is why you will see it running again when you login with the second user.

Brian R. Bondy