How does a Windows service differ from a standard exe?

后端 未结 5 755
梦毁少年i
梦毁少年i 2021-01-31 02:52

What\'s the difference between a Windows service and a standard exe?

5条回答
  •  梦如初夏
    2021-01-31 03:16

    If you're talking about implementing a background operation, here are the criteria I'd recommend to choose a service or a window-less .exe:

    Choose an exe if:

    • You need it to run on a per-user basis and only when a user is logged in
    • You need it to interact with the Windows desktop (notification icons, etc.)
    • It needs all the privileges of the logged-in user (no more, no less)

    Choose a service if:

    • It may need to run when no one is logged in
    • It doesn't generally need per-user data or privilege
    • It solely communicates with the network
    • It needs to expose new "securable" objects. Objects that have their own Declarative Access Control Lists (DACL's) that limit access to certain accounts/groups.
    • It needs special permissions that may not be available to the logged-in user.

    Services can easily be security holes, so prefer .exe's to services. Sometimes you'll need both. A virus checker needs to be able to access every file on the filesystem (which the current user may not be able to do), but it also needs to provide info to the user in the form of notification dialogs/pop-ups and a tool tray icon. Services can't interact with the user's GUI directly. They can use the standard Windows IPC (inter-process communication) services such as pipes and shared memory regions. Such tools usually have both a service and a per-user windowless .exe that communicates with the service using Windows pipes or shared memory regions.

    Get "Programming Windows Security" by Keith Brown if you want to dive into these topics.

提交回复
热议问题