Discussion:
CAN NOT Get() instance using Display Name of Service
(too old to reply)
gata
2006-06-30 07:01:01 UTC
Permalink
I test for getting service instance with following script.
1st Get() is success, but 2nd Get() is error.
Why?

-----------------------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")

' 1. get instance using Name of Service
strWQL = "Win32_Service.Name='Spooler'"
Set objService = objWMIService.Get(strWQL)

If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If

' 2. get instance using Display Name of Service
strWQL = "Win32_Service.DisplayName='Print Spooler'"
Set objService = objWMIService.Get(strWQL)

If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If
WScript.Qui
-----------------------------------------------------------------------------------------------
Jonathan Liu [MSFT]
2006-08-01 17:22:26 UTC
Permalink
The error you are getting should be "Invalid Object Path". When doing a GET
you need to provide the correct objec tpath which includes the Key
properties.

If you want the second Get() to work you need to change it to a ExecQuery.

strWQL = "select * From Win32_Service where DisplayName='Print Spooler'"
Set myServiceCollection = objWMIService.ExecQuery(strWQL)

If Not objWMIService Is Nothing Then
For each myService in myServiceCollection
WScript.Echo myService.State & vbTab & " : " & myService.Name & "
[" & myService.DisplayName & "]"
Next
End If
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Post by gata
I test for getting service instance with following script.
1st Get() is success, but 2nd Get() is error.
Why?
-----------------------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
' 1. get instance using Name of Service
strWQL = "Win32_Service.Name='Spooler'"
Set objService = objWMIService.Get(strWQL)
If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If
' 2. get instance using Display Name of Service
strWQL = "Win32_Service.DisplayName='Print Spooler'"
Set objService = objWMIService.Get(strWQL)
If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If
WScript.Quit
-----------------------------------------------------------------------------------------------
gata
2006-08-02 01:21:01 UTC
Permalink
Thank you, Jonathan, your reply.
And I'm sorry to crros post to microsoft.public.scripting.vbscript

I solved the problem already with own power.
See following..
http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?&lang=en&cr=us&guid=&sloc=en-us&dg=microsoft.public.scripting.vbscript&p=1&tid=d21575f0-50a7-4225-9df9-2e40bb42cd1b&mid=4be7f624-797c-4699-b774-8ba58119a168
Post by Jonathan Liu [MSFT]
The error you are getting should be "Invalid Object Path". When doing a GET
you need to provide the correct objec tpath which includes the Key
properties.
If you want the second Get() to work you need to change it to a ExecQuery.
strWQL = "select * From Win32_Service where DisplayName='Print Spooler'"
Set myServiceCollection = objWMIService.ExecQuery(strWQL)
If Not objWMIService Is Nothing Then
For each myService in myServiceCollection
WScript.Echo myService.State & vbTab & " : " & myService.Name & "
[" & myService.DisplayName & "]"
Next
End If
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Post by gata
I test for getting service instance with following script.
1st Get() is success, but 2nd Get() is error.
Why?
-----------------------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
' 1. get instance using Name of Service
strWQL = "Win32_Service.Name='Spooler'"
Set objService = objWMIService.Get(strWQL)
If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If
' 2. get instance using Display Name of Service
strWQL = "Win32_Service.DisplayName='Print Spooler'"
Set objService = objWMIService.Get(strWQL)
If Not objService Is Nothing Then
WScript.Echo objService.State & vbTab & " : " & objService.Name & " [" &
objService.DisplayName & "]"
End If
WScript.Quit
-----------------------------------------------------------------------------------------------
Loading...