dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: VB5,VB6,Win2K
Expertise: Intermediate
Feb 6, 2001

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


ServiceCommand - Start, stop, pause, continue a service using Active Directory

Private Enum CommandOpConstants
    cocStart = 1
    cocStop
    cocPause
    cocContinue
End Enum

' Start, Stop, Pause or Continue a service using Active Directory
' Returns True if successful
'
' NOTE: requires a reference to the Active DS Type library

Function ServiceCommand(ByVal ServiceName As String, _
    ByVal CommandOp As CommandOpConstants) As Boolean
    Dim thisComputer As ActiveDs.IADsComputer
    Dim thisService As ActiveDs.IADsServiceOperations
    ' we need this object to retrieve computer name
    Dim sysInfo As New ActiveDs.WinNTSystemInfo
    
    On Error Resume Next
   
    ' retrieve the AD object corresponding to this computer
    Set thisComputer = GetObject("WinNT://" & sysInfo.ComputerName & _
        ",computer")
    ' get the reference to the service
    Set thisService = thisComputer.GetObject("Service", ServiceName)
    
    ' perform the requested operation
    Select Case CommandOp
        Case cocStart
            thisService.Start
        Case cocStop
            thisService.Stop
        Case cocPause
            thisService.Pause
        Case cocContinue
            thisService.Continue
    End Select
    
    ' return True if there was no error
    ServiceCommand = (Err.Number = 0)

End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date