What can Services do under Windows?

后端 未结 5 472
谎友^
谎友^ 2021-01-03 15:04

Does anyone have a good guide to capabilities of Windows Services under XP? In particular, I am trying to find out what happens when a program being run as a service tries t

相关标签:
5条回答
  • 2021-01-03 15:27

    Generally, services should be designed to not have any visible UI. The entire point of a service is to run in the background, without UI, unattended. (Think SQL Server, IIS, etc.)

    In most scenarios, a separate application controls the service's operation, should a GUI be needed. (Continuing the samples I just mentioned, SQL Server Management Studio, IIS Manager, etc.) These separate applications configure and manipulate the service (and occasionally, if needed, bounce said service).

    If your service requires occasional UI, and said UI can't be isolated to a control app, then you probably should reconsider the fact that you're using a service to begin with. Perhaps a UI application which resides in the system notification area is the right pattern to use? (E.G., Windows Live Communicator.)

    0 讨论(0)
  • 2021-01-03 15:29

    A service in Windows XP can interact with the Desktop if its "Allow Service to Interact with Desktop" property (MMC -> service properties -> Log On tab) is checked. It is also possible to do so by doing the following:

    hWinstation = OpenWindowStation("winsta0", FALSE, MAXIMUM_ALLOWED);
    SetProcessWindowStation(hWinstation);
    hDesktop = OpenDesktop("default", 0, FALSE, MAXIMUM_ALLOWED);
    SetThreadDesktop(hDesk);
    

    But be aware that presenting UI from a service process in Windows XP will almost always lead to a security problem (see Shatter attack). You should try to break out the UI part of your application from the service.

    0 讨论(0)
  • 2021-01-03 15:31

    If you should be thinking of eventually migrating to a newer OS such as Vista or Server 2008, you will find that you cannot give a service permission to interact with the desktop at all. Therefore, from the point of view of forwards compatibility, you should design your service to not require it.

    0 讨论(0)
  • 2021-01-03 15:41

    A service in Microsoft Windows is a program that runs whenever the computer is running the operating system. It does not require a user to be logged on. Services are needed to perform user-independent tasks such as directory replication, process monitoring, or services to other machines on a network, such as support for the Internet HTTP protocol

    Usually it is implemented as a console application that runs in the background and performs tasks that don't require user interaction.

    The installed services can be configured through the Services applet, available from Control Panel --> Administrative Tools in Windows 2000/XP.

    Services can be configured to start automatically when operating system starts, so you dont have to start each of them manually after a system reboot.

    1. Creating a Simple Service - MSDN Article
    2. Writing Windows Services Made easy - Code Project Article
    3. Five Steps to Writing Windows Services in C - DevX Article
    0 讨论(0)
  • 2021-01-03 15:49

    Usually the service won't have permission to write to the window station and desktop, so it will fail; even running applications that load user32.dll can fail simply because user32 has initialization code that wants to talk to the window station and can't get access to it unless the service is running as an administrator.

    0 讨论(0)
提交回复
热议问题