Starting, Pausing, and Stopping NT Services
You can use ADSI to manage local and remote services. This code shows and describes the different methods and properties ADSI provides for services. Please vote and leave your comments for this submission.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Option Explicit
Public Function Services() As Boolean
Dim oCol As New Collection
Dim oSysInfo As New ActiveDs.WinNTSystemInfo
Dim oComp As ActiveDs.IADsComputer
Dim oSvc As ActiveDs.IADsServiceOperations
Dim sCompName As String
On Error Resume Next
Services = False
sCompName = "WinNT://" & oSysInfo.ComputerName & ",computer"
Set oComp = GetObject(sCompName)
oComp.Filter = Array("Service")
For Each oSvc In oComp
Debug.Print "Service display name = " & oSvc.DisplayName
Debug.Print "Service name = " & oSvc.Name
Debug.Print "Service account name = " & oSvc.ServiceAccountName
Debug.Print "Service executable = " & oSvc.Path
Debug.Print "Current status = " & oSvc.Status & vbCrLf
If oSvc.Status = 4 Then
'Show only running services
cboService.AddItem oSvc.Name
End If
Next
Set oSvc = Nothing
Set oComp = Nothing
Set oSysInfo = Nothing
Services = True
End Function
Private Sub cmdStop_Click()
Dim oSysInfo As New ActiveDs.WinNTSystemInfo
Dim oComp As ActiveDs.IADsComputer
Dim oSvc As ActiveDs.IADsServiceOperations
Dim sCompName As String
Dim sSvc As String
sSvc = cboService.Text
sCompName = "WinNT://" & oSysInfo.ComputerName & ",computer"
Set oComp = GetObject(sCompName)
Set oSvc = oComp.GetObject("Service", sSvc)
oSvc.Stop
Set oSvc = Nothing
Set oComp = Nothing
Set oSysInfo = Nothing
End Sub
Private Sub Form_Load()
Services
End Sub
Original Comments (3)
Recovered from Wayback Machine