Alex K. Angelopoulos said:
Besides Jonathan's suggestion, let me mention something that you should
always consider when you want to reach outside of Word to do things with
services, accounts, and systems on NT family systems
(NT/2000/XP/2003/Longhorn) you almost certainly want to try using WMI or
ADSI.
I have three books on VBA and none of them have a reference to WMI or
ADSI in them.
If you aren't familiar with either buzzword, both refer to standard COM
tools for accessing Windows systems and domain directories. They're common
scripting interfaces, and due to the similarities between VBScript and VBA
syntax, you can easily grab code examples in
microsoft.public.scripting.vbscript that will run in VBA - and typically run
faster, as well.
I was however able to adapt a script I found in the vbscript forum you
mentioned (copied below). This seems a bit long winded though so I'm
going to take a look at Jonathan's Task idea to see if I simplify
things a bit. After I find out how to start a service that it!
Thanks for the advice.
Regards,
Colin
===========================================================================
Declare Function GetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub Main
msgbox IsThisServiceRunning("CA-OpenIngres_Client")
End Sub
'-- Get name of users computer
Function LocalComputerName()
Dim Buffer As String, size As Long, iret As Long
Buffer = Space(255)
size = 255
iret = GetComputerName(Buffer, size)
LocalComputerName = Left$(Buffer, size)
End Function
'-- Check service is running
Function IsThisServiceRunning(ServiceName)
Const ADS_SERVICE_RUNNING = 4
IsThisServiceRunning = False
On Error Resume Next
Set oComputer = GetObject("WinNT://" & LocalComputerName &
",computer")
Set oService = oComputer.GetObject("Service", ServiceName)
If oService.status = ADS_SERVICE_RUNNING Then IsThisServiceRunning =
True
Set oComputer = Nothing
Set oService = Nothing
On Error GoTo 0
End Function
===========================================================================