Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal fInherit As Integer, ByVal hObject As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Sub Example()
'returns a 0 if all is well
'returns a 1 if it fails
'returns a 2 if the action committed is already in progress or if it does not support the action
Debug.Print Service("AeLookupSvc", "start")
Debug.Print Service("AeLookupSvc", "pause")
Debug.Print Service("AeLookupSvc", "continue")
Debug.Print Service("AeLookupSvc", "stop")
End Sub
Function Service(ServiceName As String, Action As String) As Long
Dim ExitCode As Long, ProcHwnd As Long
ExitCode = -1
ProcHwnd = OpenProcess(&H400, False, Shell("net " & Action & " " & ServiceName, vbHide))
Do
GetExitCodeProcess ProcHwnd, ExitCode
DoEvents
Loop While ExitCode = &H103
Service = ExitCode
End Function