Archived from groups: microsoft.public.vc.language,microsoft.public.windowsnt.setup (More info?) "mustang" <kakyung@hotmail.com> wrote in message news:5f390e01.0502011115.51bfe213@posting.google.com... > I have written a NT service that uses Winsock. OK. > This works fine until I logoff. When logoff happenes, the service just > dies without much clue. System event log shows that "the service > terminated unexpectedly..." This is an educated guess: Does you service create any windows? Are they visible when the user logs off? If you are using boilerplate code (MFC, etc) for the shell of your service then it may be that that when your window is closed at loggof, the boilerplate's WM_CLOSE message handler (or perhaps the WM_ENDSESSION handler) does a DestroyWindow() on your main window which causes a WM_DESTROY message whose handler does a PostQuitMessage(0) which terminates the application. That would be bad. <g> If that's the problem it is useful to point out that that behavior is _one_ of the main reasons why services should NOT interact with the desktop and that boilerplate code originally developed for desktop applications is NEVER (OK rarely if one is less headstrong than I <g>) a good idea in a service. If that's not the problem then please excuse the rant. :-) > The service is running under "Local System" account and "Allow service > to interact with desktop" is NOT checked. Not only does the interactive option allow just any old user to stop a service, it opens up a system to the "Shatter" attack. You can google for the details. To sum up, even though it is more work, services you develop should NOT be interactive. Any UI chores should be handled by an ordinary Windows client application - perhaps autostarted at login - which uses some inter-process communication mechanism to get the service to do its bidding. If you do that, the service behaves predictably, only ever doing what your client is programmed to ask it to do. > Has anyone encountered similar problem? Not I. But I wouldn't consider either using MFC in a service or allowing it do interact with the desktop. Regards, Will |
|
来自: 昵称14903431 > 《Windows》