Get NT Running Services List

C

Colin Steadman

I've got a template that connects to an Ingres database using
IngresNet.

This works fine, but sometimes (for unknown reasons) IngresNet doesn't
start when the user logs. And when this happens the template
obviously doesn't work.
I would therefore like to check if the IngresNet service is running,
which would allow me to start it if is'nt.

My question is therefore, is there a method in VBA (Word 2000) I could
use to check which services are running on an NT machine?

TIA,

Colin
 
J

Jonathan West

Hi Colin,

I don't know whether the IngresNet service will appear there, but you could
start out by checking the Tasks collection to see if is it listed there.
 
C

Colin Steadman

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

===========================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top