471,354 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 software developers and data experts.

SWbemObjectEx not found

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").SpawnInst ance_
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.SWbemLocat or")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9' ")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInst ance_()
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.
Dec 24 '07 #1
2 4929
On Dec 24, 1:01 pm, jmgmail <jin...@gmail.comwrote:
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").SpawnInst ance_
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.SWbemLocat or")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9' ")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInst ance_()
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
Dec 25 '07 #2
jmgmail wrote:
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").SpawnInst ance_
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.SWbemLocat or")
locator.Security_.impersonationlevel = 3
Services = locator.ConnectServer("smsroot1","root/SMS/site_A")
instCollection = Services.Get("SMS_Collection.CollectionID='A000D9' ")

instDirectRule =
Services.Get("SMS_CollectionRuleDirect").SpawnInst ance_()
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
Dec 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by amywolfie | last post: by
2 posts views Thread by ypul | last post: by
14 posts views Thread by NormD | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.