Option Explicit
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long
Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Private Sub Form_Load()
Dim strMachine As String
Dim strDatabase As String
Dim lRet As Long
'Try with an empty string first
'strMachine = "COMPNAME" ' leave this empty to connect to the local computer
lRet = OpenSCManager(strMachine, strDatabase, SC_MANAGER_ENUMERATE_SERVICE)
If lRet <> 0 Then
'you connected so close the handle
CloseServiceHandle lRet
Else
'call did not work
MsgBox "Call failed"
End If
End Sub