![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 sc \\PC1 query w32time | find /i "Service_Name" || echo Service w32time not found |
My System Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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! > |
My System Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||