SWbemObjectEx not found

J

jmgmail

I have a working VBScript and failed to convert it to Python. Can
someone help?

==VBScript:==
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
Set instCollection =
Services.Get("SMS_Collection.CollectionID='A000D9'")

'Create the direct rule.
Set instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

'Add the direct rule to the collection.
instCollection.AddMembershipRule instDirectRule
==END==

==Python==
import sys,os,getopt
import win32com.client

locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9'")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_()
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

instCollection.AddMembershipRule(instDirectRule)
==END==

The error from Python is:
Traceback (most recent call last):
File "C:\temp\pushpkg.py", line 19, in ?
instCollection.AddMembershipRule(instDirectRule)
File "C:\Python24\lib\site-packages\win32com\client\dynamic.py",
line 491, in
__getattr__
raise pythoncom.com_error, details
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'SWbemObjectEx',
'Not found ', None, 0, -2147217406), None)
==END==

Spend a whole day on this already and still have no clue.

Thank you.
 
K

kyosohma

I have a working VBScript and failed to convert it to Python. Can
someone help?

==VBScript:==
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
Set instCollection =
Services.Get("SMS_Collection.CollectionID='A000D9'")

'Create the direct rule.
Set instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

'Add the direct rule to the collection.
instCollection.AddMembershipRule instDirectRule
==END==

==Python==
import sys,os,getopt
import win32com.client

locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9'")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_()
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

instCollection.AddMembershipRule(instDirectRule)
==END==

The error from Python is:
Traceback (most recent call last):
File "C:\temp\pushpkg.py", line 19, in ?
instCollection.AddMembershipRule(instDirectRule)
File "C:\Python24\lib\site-packages\win32com\client\dynamic.py",
line 491, in
__getattr__
raise pythoncom.com_error, details
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
'SWbemObjectEx',
'Not found ', None, 0, -2147217406), None)
==END==

Spend a whole day on this already and still have no clue.

Thank you.

I'm not seeing the error either. You should post to the PyWin32
mailing list as they have more experience there:

http://mail.python.org/mailman/listinfo/python-win32

Plus, Mark Hammond occasionally answers questions there too. He wrote
(or co-wrote) the module, FYI.

Mike
 
T

Tim Golden

jmgmail said:
I have a working VBScript and failed to convert it to Python. Can
someone help?

==VBScript:==
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
Set instCollection =
Services.Get("SMS_Collection.CollectionID='A000D9'")

'Create the direct rule.
Set instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

'Add the direct rule to the collection.
instCollection.AddMembershipRule instDirectRule
==END==

Couple of points here. First off, this is standard WMI stuff
in spite of the slightly awkward way the VBS appears, so if
I may recommend my own WMI module [1] you may find that
easier. Secondly, this will be difficult for anyone to debug
in any depth without having access to the WMI-provided SMS
namespace. But I'll do my best!
==Python==
import sys,os,getopt
import win32com.client

locator = win32com.client.Dispatch("WbemScripting.SWbemLocator")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9'")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInstance_()
instDirectRule.ResourceClassName = "SMS_R_System"
instDirectRule.ResourceID = 8566
instDirectRule.RuleName = "MyDirectRule"

instCollection.AddMembershipRule(instDirectRule)
==END==

Almost certainly your problem here is that VBS is doing
some slightly fancy stuff behind the scenes to set up
this method call, which you'll have to do for yourself in
Python. Try replacing that last line with (untested, obviously):

<code-snippet>
AddMembershipRule = instCollection.Methods_ ("AddMembershipRule")
InParameters = AddMembershipRule.InParameters
#
# might be 1-indexed; not sure
#
InParameters[0] = instDirectRule
instCollection.ExecMethod_ ("AddMembershipRule", InParameters)

</code-snippet>

Come back if that doesn't help or if it isn't clear what's going
on.

TJG

[1] http://timgolden.me.uk/python/wmi.html
 

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

Members online

Forum statistics

Threads
474,289
Messages
2,571,435
Members
48,120
Latest member
Natbelix

Latest Threads

Top