AR Services Manager Library 1.03

This library manages Windows services. It is a COM component.

 

If used in exe, copy ARServicesMgr.DLL from QM folder to your exe folder on other computers. Don't need to register COM component.

 

Example - enumerate services

Services.clsServices ses._create
Services.clsService se
foreach se ses
	out se.DisplayName
	

 

Example - state, start etc

Services.clsService se._create
BSTR dispName="Quick Macros"
se.DisplayName=dispName
if(!se.ServiceType) mes- "Service not found." "" "x"

str state
sel se.CurrentState
	case Services.Stopped state="stopped"
	case Services.Start_Pending_20 state="start pending"
	case Services.Stop_Pending_20 state="stop pending"
	case Services.Running state="running"
	case Services.continue_pending_20 state="continue pending"
	case Services.Pause_Pending_20 state="pause pending"
	case Services.Paused state="paused"
	case else state="unknown"

int i=ListDialog("Start[]Stop[]Pause[]Continue" F"Current state: {state}")
if(!i) ret
if(!IsUserAdmin) mes- "To change service state, QM must be running as admin." "" "x"
sel i
	case 1 se.StartService
	case 2 se.StopService
	case 3 se.PauseService
	case 4 se.ContinueService

 

The classes included in this library are:

 

clsServices
This class can be used to list and access services in a system. You can specify what type of services to want to have listed.
Properties:
  • ComputerName. By default, this property is set to the name of the computer in which the library is running. You can specify the name of another computer to access the services running there.
  • Count. Number of services listed.
  • Item(Index). This property will take you to a clsService object that contains the properties and the methods to access the service specified. You can specify a service by putting the number that is has in the collection or by passing its name.
  • ServicesEnumState. The possible values for this property are: Active Services, Both Active and Inactive Services or Inactive Services. Specify here what type of services you want to list. The library will update itself if this property is changed.
  • ServicesEnumType. The possible values for this property are: WIN32 Services, Kernel and File System Drivers or Both WIN32 and Drivers. Specify here what type of services you want to have listed. The library will update itself if this property is changed.
Methods:
  • Delete(Index). Pass the number that a service has in the collection or the name of a service to delete it. The method returns True (nonzero) if successful or False (0) if there was an error. After you delete a service, it is not immediately removed from the services, if it has references to it. If you try to call the function again after you got True (successful), the method will return False.
  • Refresh. Call this method to refresh the contents of the object. Returns True if successful or False if there was an error.

 

clsService
This class is returned by the clsServices class (one per service listed), but you can also use it independently to access a specific system, in the local machine or through a network. To access a specific service, just set the name or the display name of the service you want to access. The class will update itself automatically with the information of the service. Using this class you can also start, stop, pause or continue services.
(r/w) means read/write property; (r-o) means read-only property.
Properties:
  • AutoUpdate (r/w). If this property is True (nonzero), when you tell the service to change its state (stop it, start it, pause it...) the library will start checking for the state of the service till its state changes completely or till the time specified in AutoUpdateTimeOut expires. This is because usually a service doesn't change its state immediately, but needs some time for processing. Therefore, before when you changed the state of a service, the CurrentState property passed to something like 'Start Pending', and after that you had to refresh the state manually. This property is automatically True if you are using this class independently, and automatically False if you are accessing from a clsServices class.
  • AutoUpdateInterval (r/w). How often the library will refresh the status of the service, given in milliseconds.
  • AutoUpdateTimeOut (r/w). If the service doesn't change its status, for how long the library should keep refreshing its contents, in milliseconds.
  • BinaryPathName (r/w). Path to the binary file of the service.
  • CheckPoint.
  • ComputerName (r/w). By default, this property is empty if you are using this class independently, or has the same value as the class clsServices is this class is an item of the other. You can specify another name to access a service in another computer.
  • ControlsAccepted (r-o). Possible values are: Accept Pause & Continue, Accept Shutdown or Accept Stop. Also, it could be any combination of these values. To know if a service accepts a certain control, use operator &. Example: if(Svc.ControlsAccepted&Accept_Stop_20).
  • CurrentState (r/w). Possible values are: Continue Pending, Pause Pending, Paused, Running, Start Pending, Stop Pending or Stopped. You can also set this property to Start, Stop or Pause to modify the state of the service.
  • Dependencies (r/w). This property will return an object that contains the dependencies of the service, if any. You can also create this class independently and set it to this property to change the dependencies of the service.
  • DisplayName (r/w). Display name for the service (those you can see in the services control manager). If you change this property, the class will look for another service that has that display name, and if it finds it, it will update itself with the information of that service.
  • LoadOrderGroup (r/w).
  • Name (r/w). Internal name of the service. You can change this property to the name of other service, and the class will update itself with the configuration of that service.
  • Password (r/w). You can use this property to change the password of the account under which a service is run. If you do it, this property will also contain that password if the change is successful. If it is not, or you haven't changed the password, this property will be empty (what doesn't mean that the account doesn't have any password).
  • ServiceSpecificExitCode (r-o).
  • ServiceType (r/w). Possible values are: File System Driver, Kernel Driver, WIN32 Own Process, WIN32 Share Process, Interactive WIN32 Own Process or Interactive WIN32 Share Process.
  • StartErrorSeverity (r/w). Possible values are: Ignore Error, Normal Error, Severe Error ore Critical Error. Informs on how there server will act if an error ocurres at startup.
  • StartName (r/w). Depending on the type of service, this can be the name of the account under which the service is running.
  • StartType (r/w). Possible values are: Auto Start, Boot Start, Demand Start, Disabled, System Start. Indicates how the service is started.
  • TagID (r/w).
  • WaitHint (r-o).
  • Win32ExitCode (r-o).
Methods:
  • ChangeAccount(strUserID, strPassword, [strDomain]). If you want to change the account under which a WIN32_OWN_Process service is run, you can't use the StartName and Password properties independently, since both must be changed at the same time. Use this method instead.
  • ChangeDisplayName(strDisplayName). You can't use the DisplayName property because if you change it, the class will just look for another service with that display name, instead of changing that property for the current service. Use this method instead.
  • ContinueService. Use this method to continue the service if it is paused. Returns True of successful or False if an error ocurred.
  • PauseService.Use this method to pause a service if it is running. Returns True of successful or False if an error ocurred.
  • StartService. Use this method to start a service if it is stopped. Returns True of successful or False if an error ocurred.
  • StopService. Use this method to stop a service if it is running. Returns True of successful or False if an error ocurred.
  • Refresh. Forces the library to update the information about the service. Returns True of successful or False if an error ocurred.
Events:
  • StateChanged(lNewState). This event is fired when the service changes its status.

 

clsSVCDependencies
This object is used to manage dependencies of the services.
Properties:
  • Count. Number of dependencies being listed.
  • Item(lIndex). Pass a number and this property returns the dependency that has that number in the collection.
  • Source. This property returns a char 0 divided string with the dependencies. This is how they are originally given by the system.
Methods:
  • Add(strCad). Use this method to add a dependency to the object.
  • Remove(lIndex). Use this method to remove dependencies from the object.

 

© Alvaro Redondo, 1998. All Rights Reserved.
http://www.sevillaonline.com/ActiveX