Hello There

I am writing a script to query for services of a particular name, at this
stage I am just echoing out the status of the service, this so far is
working, I then tried to catch it when the query found no services, and so
far I cant.

I have fudged it together with a count but I really don't want to leave it
like that, so I was hoping someone could have a look at it for me and tell
how I could do it better

Just remove the % for it not to find the Print service
<SNIP>
SERVICE_NAME = "Print%"
Count = 0

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName Like '" &
SERVICE_NAME & "'")

For Each objService in colServiceList
Count = Count +1
Next
If Count > 0 Then
For Each objService in colServiceList
Wscript.Echo objService.State
Next
Else
Wscript.Echo "No Service Found"
END IF
</SNIP>

TIA

Re: Error on no results by JHP

JHP
Wed Sep 14 13:12:14 CDT 2005

SERVICE_NAME = "Print%"

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where DisplayName Like '" &
SERVICE_NAME & "'")

If colServiceList.Count > 0 Then
For Each objService in colServiceList
Wscript.Echo objService.State
Next
Else
Wscript.Echo "No Service Found"
End If

"Gary" <Gary@discussions.microsoft.com> wrote in message
news:0530930F-5AF7-4BAF-A5B6-5BDED5BEC65C@microsoft.com...
> Hello There
>
> I am writing a script to query for services of a particular name, at this
> stage I am just echoing out the status of the service, this so far is
> working, I then tried to catch it when the query found no services, and so
> far I cant.
>
> I have fudged it together with a count but I really don't want to leave it
> like that, so I was hoping someone could have a look at it for me and tell
> how I could do it better
>
> Just remove the % for it not to find the Print service
> <SNIP>
> SERVICE_NAME = "Print%"
> Count = 0
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
>
> Set colServiceList = objWMIService.ExecQuery _
> ("Select * from Win32_Service where DisplayName Like '" &
> SERVICE_NAME & "'")
>
> For Each objService in colServiceList
> Count = Count +1
> Next
> If Count > 0 Then
> For Each objService in colServiceList
> Wscript.Echo objService.State
> Next
> Else
> Wscript.Echo "No Service Found"
> END IF
> </SNIP>
>
> TIA
>
>



Re: Error on no results by Gary

Gary
Thu Sep 15 05:58:02 CDT 2005

Thank you very much

Gary

"JHP" wrote:

> SERVICE_NAME = "Print%"
>
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> Set colServiceList = objWMIService.ExecQuery _
> ("Select * from Win32_Service where DisplayName Like '" &
> SERVICE_NAME & "'")
>
> If colServiceList.Count > 0 Then
> For Each objService in colServiceList
> Wscript.Echo objService.State
> Next
> Else
> Wscript.Echo "No Service Found"
> End If
>
> "Gary" <Gary@discussions.microsoft.com> wrote in message
> news:0530930F-5AF7-4BAF-A5B6-5BDED5BEC65C@microsoft.com...
> > Hello There
> >
> > I am writing a script to query for services of a particular name, at this
> > stage I am just echoing out the status of the service, this so far is
> > working, I then tried to catch it when the query found no services, and so
> > far I cant.
> >
> > I have fudged it together with a count but I really don't want to leave it
> > like that, so I was hoping someone could have a look at it for me and tell
> > how I could do it better
> >
> > Just remove the % for it not to find the Print service
> > <SNIP>
> > SERVICE_NAME = "Print%"
> > Count = 0
> >
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\.\root\cimv2")
> >
> > Set colServiceList = objWMIService.ExecQuery _
> > ("Select * from Win32_Service where DisplayName Like '" &
> > SERVICE_NAME & "'")
> >
> > For Each objService in colServiceList
> > Count = Count +1
> > Next
> > If Count > 0 Then
> > For Each objService in colServiceList
> > Wscript.Echo objService.State
> > Next
> > Else
> > Wscript.Echo "No Service Found"
> > END IF
> > </SNIP>
> >
> > TIA
> >
> >
>
>
>