The SuperSCP Sample Application

[Previous] [Next]

The SuperSCP sample application ("04 SuperSCP.exe") is an SCP that does just about anything and everything you can imagine to a service. The source code and resource files for the application are in the 04-SuperSCP directory on the companion CD. When you start the program, the window in Figure 4-2 appears.

click to view at full size.

Figure 4-2. The interface for the SuperSCP sample application

The application initializes by querying the local machine's computer name, and it places this name in the Machine field. Then the application communicates with this machine's SCM, enumerating all the installed services and placing each service's internal name into the Internal Name field's combo box. At any time, you can administer the services on a remote machine by entering the remote machine's name in the Machine field and clicking the Refresh button.

As you select entries from the Internal Name field, all the remaining fields are updated. You can change any combination of settings for a service and then click the Reconfigure button to make the changes permanent. Clicking the Security button allows you to alter the security of the selected service. You can also mark a selected service for deletion from the SCM's database by clicking the Remove button. If you are going to perform a number of tasks with the SCM, you can lock it using the Lock SCM button.

To add a new service to the SCM's database, just type the desired internal name into the Internal Name field. If the internal name field contains a value that does not match an existing service's internal name, SuperSCP assumes that the fields describe a new service that you'd like to add to the SCM's database. After entering the internal name of the new service, configure the service any way you'd like. Use the Browse button to help you locate the service's executable file. Also, if you drag and drop an executable file from a folder into the SuperSCP window, the pathname will appear in the Pathname field. Once you've configured the service's settings, click the Create button to add the new service to the SCM's database.

At the bottom of the window is the execution control section which allows you to alter the execution of the service. All the buttons in this section are self-explanatory. On the right is a list box that receives a new entry every second. Each entry indicates an entry number and the service's current state: Stopped, Start Pending, Stop Pending, Running, Continue Pending, Pause Pending, or Paused. After the state is shown, the most recent checkpoint and wait hint reported by the service are shown. The last two fields, WErr and SErr, show the last Win32 error code and service-specific error code reported by the service.

As far as the code goes, nothing is tricky. It's all just a matter of calling the right SCP function at the right time. However, a number of reusable C++ classes do make the implementation significantly easier. The two main C++ classes are CSCMCtrl and CServiceCtrl. The CSCMCtrl class is a thin wrapper on top of SCP functions that talk directly to the SCM. The CSCMCtrl methods include Open, LockDatabase, QueryLockOwner, GetInternalName, and GetDisplayName. In addition, there are methods for creating a snapshot of the SCM's services and enumerating through them. The C++ class really helps here because it handles all of the memory management issues internally.

The CServiceCtrl class is a thin wrapper on top of SCP functions that talk directly to a service. The CServiceCtrl methods include InstallAndOpen, Open, Delete, Start, Control, WaitForState, QueryStatus, QueryConfig, QueryDescription, ChangeConfig, QueryFailureActions, ChangeFailureActions, and EditSecurity. Methods for creating a snapshot of a service's dependencies also exist. Again, the C++ class comes in handy because many of these methods' memory management issues are handled internally.



Programming Server-Side Applications for Microsoft Windows 2000
Programming Server-Side Applications for Microsoft Windows 2000 (Microsoft Programming)
ISBN: 0735607532
EAN: 2147483647
Year: 2000
Pages: 126

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net