Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - simple question - check services exist

Reply
 
Old 09-22-2009   #1 (permalink)
KeithK


 
 

simple question - check services exist

How can I check if more than one service exists? I have the following script
which checks for one service.

--------------------------
Sub Main()
Call CheckServiceExists (strComputer,"service1")
If bolServiceExists = True Then
' Call StartLog() 'DBG
' logFile.WriteLine("DBG - Service: service1" & vbTab & "Status: Service
Exists")
Exit Sub

My System SpecsSystem Spec
Old 09-22-2009   #2 (permalink)
KeithK


 
 

RE: simple question - check services exist

CheckServiceExist is a function:

Function CheckServiceExists(strComputer,strService)
Dim objWMIService, colServiceList
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName = '" & strService &
"'")
If colServiceList.Count = 0 Then
bolServiceExists = False
Else
bolServiceExists = True
End If
End Function

"KeithK" wrote:
Quote:

> How can I check if more than one service exists? I have the following script
> which checks for one service.
>
> --------------------------
> Sub Main()
> Call CheckServiceExists (strComputer,"service1")
> If bolServiceExists = True Then
> ' Call StartLog() 'DBG
> ' logFile.WriteLine("DBG - Service: service1" & vbTab & "Status: Service
> Exists")
> Exit Sub
My System SpecsSystem Spec
Old 09-22-2009   #3 (permalink)
Pegasus [MVP]


 
 

Re: simple question - check services exist


"KeithK" <KeithK@newsgroup> wrote in message
news:CBAC2A8C-5CDE-4655-8BEF-17C74CCDAEF8@newsgroup
Quote:

> How can I check if more than one service exists? I have the following
> script
> which checks for one service.
>
> --------------------------
> Sub Main()
> Call CheckServiceExists (strComputer,"service1")
> If bolServiceExists = True Then
> ' Call StartLog() 'DBG
> ' logFile.WriteLine("DBG - Service: service1" & vbTab & "Status: Service
> Exists")
> Exit Sub
This particular wheel has already been invented at the Command Prompt:
sc \\PC1 query w32time | find /i "Service_Name" || echo Service w32time not
found


My System SpecsSystem Spec
Old 09-22-2009   #4 (permalink)
KeithK


 
 

Re: simple question - check services exist

The question was "more" than one service.

Also, CheckServiceExist is a function:

Function CheckServiceExists(strComputer,strService)
Dim objWMIService, colServiceList
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName = '" & strService &
"'")
If colServiceList.Count = 0 Then
bolServiceExists = False
Else
bolServiceExists = True
End If
End Function
---------------------
Thanks!

"Pegasus [MVP]" wrote:
Quote:

>
> "KeithK" <KeithK@newsgroup> wrote in message
> news:CBAC2A8C-5CDE-4655-8BEF-17C74CCDAEF8@newsgroup
Quote:

> > How can I check if more than one service exists? I have the following
> > script
> > which checks for one service.
> >
> > --------------------------
> > Sub Main()
> > Call CheckServiceExists (strComputer,"service1")
> > If bolServiceExists = True Then
> > ' Call StartLog() 'DBG
> > ' logFile.WriteLine("DBG - Service: service1" & vbTab & "Status: Service
> > Exists")
> > Exit Sub
>
> This particular wheel has already been invented at the Command Prompt:
> sc \\PC1 query w32time | find /i "Service_Name" || echo Service w32time not
> found
>
>
>
My System SpecsSystem Spec
Old 09-22-2009   #5 (permalink)
Pegasus [MVP]


 
 

Re: simple question - check services exist


"KeithK" <KeithK@newsgroup> wrote in message
news:8983A0AF-87BC-4270-B4A8-F0AF018C000E@newsgroup
Quote:

> The question was "more" than one service.
>
> Also, CheckServiceExist is a function:
>
> Function CheckServiceExists(strComputer,strService)
> Dim objWMIService, colServiceList
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colServiceList = objWMIService.ExecQuery _
> ("Select * from Win32_Service where DisplayName = '" & strService &
> "'")
> If colServiceList.Count = 0 Then
> bolServiceExists = False
> Else
> bolServiceExists = True
> End If
> End Function
> ---------------------
> Thanks!
>
Do you perhaps want to get a list of *all* installed services?


My System SpecsSystem Spec
Old 09-22-2009   #6 (permalink)
KeithK


 
 

Re: simple question - check services exist

I am interested in checking for two specific services. "service1" and
"service2". Is there an "or" operator that I can use in my existing script?

"Pegasus [MVP]" wrote:
Quote:

>
> "KeithK" <KeithK@newsgroup> wrote in message
> news:8983A0AF-87BC-4270-B4A8-F0AF018C000E@newsgroup
Quote:

> > The question was "more" than one service.
> >
> > Also, CheckServiceExist is a function:
> >
> > Function CheckServiceExists(strComputer,strService)
> > Dim objWMIService, colServiceList
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> > Set colServiceList = objWMIService.ExecQuery _
> > ("Select * from Win32_Service where DisplayName = '" & strService &
> > "'")
> > If colServiceList.Count = 0 Then
> > bolServiceExists = False
> > Else
> > bolServiceExists = True
> > End If
> > End Function
> > ---------------------
> > Thanks!
> >
>
> Do you perhaps want to get a list of *all* installed services?
>
>
>
My System SpecsSystem Spec
Old 09-22-2009   #7 (permalink)
Pegasus [MVP]


 
 

Re: simple question - check services exist

Of course there is an "or" operator - see below. Note also a number of
changes I made to your code.

strComputer = "."
If ServiceExists(strComputer, "Windows Time") _
Or ServiceExists(strComputer, "xxx") _
Then WScript.Echo "One of the services exists."
' Call StartLog() 'DBG
' logFile.WriteLine("DBG - Service: service1" & vbTab & "Status: Service
Exists")

Function ServiceExists(strPC,strService)
Set objWMIService = GetObject("winmgmts:\\" & strPC & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName = '" & strService & "'")
ServiceExists = (colServiceList.Count <> 0)
End Function


"KeithK" <KeithK@newsgroup> wrote in message
news:318D25C0-9E65-4C98-827A-64A1829E73CF@newsgroup
Quote:

>I am interested in checking for two specific services. "service1" and
> "service2". Is there an "or" operator that I can use in my existing
> script?
>
> "Pegasus [MVP]" wrote:
>
Quote:

>>
>> "KeithK" <KeithK@newsgroup> wrote in message
>> news:8983A0AF-87BC-4270-B4A8-F0AF018C000E@newsgroup
Quote:

>> > The question was "more" than one service.
>> >
>> > Also, CheckServiceExist is a function:
>> >
>> > Function CheckServiceExists(strComputer,strService)
>> > Dim objWMIService, colServiceList
>> > Set objWMIService = GetObject("winmgmts:\\" & strComputer &
>> > "\root\cimv2")
>> > Set colServiceList = objWMIService.ExecQuery _
>> > ("Select * from Win32_Service where DisplayName = '" &
>> > strService &
>> > "'")
>> > If colServiceList.Count = 0 Then
>> > bolServiceExists = False
>> > Else
>> > bolServiceExists = True
>> > End If
>> > End Function
>> > ---------------------
>> > Thanks!
>> >
>>
>> Do you perhaps want to get a list of *all* installed services?
>>
>>
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Simple question .NET General
Simple Background/Color Skins for WMP 11? Do they Exist? Vista music pictures video
Simple Question? Vista General
Newbie: Nagios with nrpe_nt, check for diskspace; check services,returncode PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46