分享

NT service: terminated after user logoff

 昵称14903431 2013-12-06
        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      

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多