<div>YES!!! It works. I was able to successfully run the following version:</div>
<div> </div>
<div>###</div>
<div> </div>
<div><font face="courier new,monospace">import wmi</font></div>
<div><font face="courier new,monospace">site = 'MV1'<br>wmi_server = 'mtv-sql-2'<br>resource = 23012</font></div>
<div><font face="courier new,monospace">wmi_namespace = 'root\\sms\\site_%s' % site<br>conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)<br>coll = conn.SMS_Collection(CollectionID='MV100362')[0]</font></div>
<div><font face="courier new,monospace">rule = conn.SMS_CollectionRuleDirect.new()<br>rule.ResourceID = resource<br>rule.RuleName = 'ResourceID: ' + str(resource)<br>rule.ResourceClassName = 'SMS_R_System'</font></div>
<div><font face="courier new,monospace">result = coll.AddMembershipRule(rule)</font></div>
<div> </div>
<div>###</div>
<div> </div>
<div>I still get the error on my old code, but maybe mixing win32com.client-style objects with wmi objects is causing weirdness there. In any case, I have what I need from here on out. I'd say almost 100% of all WMI scripts out there are for getting information, not setting it, but when you're dealing with SMS it's the only way to go.</div>
<div> </div>
<div>Thanks again, and someday I'll pull a thorn out of your foot or something. :)<br><br></div>
<div class="gmail_quote">On Jan 30, 2008 1:14 AM, Tim Golden <<a href="mailto:mail@timgolden.me.uk" target="_blank">mail@timgolden.me.uk</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div></div>
<div>Tim Johnson wrote:<br>> Hmm, I'm getting a different error now. Could it be having trouble passing<br>> one wmi object as a parameter to the method of another?<br>><br>> import wmi<br>> site = 'MV1'<br>
> wmi_server = 'mtv-sql-2'<br>> resource = 23012<br>> wmi_namespace = 'root\\sms\\site_%s' % site<br>> conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)<br>> coll = conn.Get('SMS_Collection.CollectionID="MV100362"')<br>
> rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_()<br>> rule.ResourceID = resource<br>> rule.RuleName = 'ResourceID: ' +str(resource)<br>> rule.ResourceClassName = 'SMS_R_System'<br>
> coll.AddMembershipRule(rule)<br>><br>> Gives me :<br>><br>> Traceback (most recent call last):<br>> File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?<br>> coll.AddMembershipRule(rule)<br>
> File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 491,<br>> in __getattr__<br>> raise pythoncom.com_error, details<br>> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,<br>
> 'SWbemObjectEx', 'Not found ', None, 0, -2147217406), None)<br>><br>> But this:<br>><br>> import wmi<br>> site = 'MV1'<br>> wmi_server = 'mtv-sql-2'<br>> resource = 23012<br>
> wmi_namespace = 'root\\sms\\site_%s' % site<br>> conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)<br>> coll = conn.SMS_Collection(CollectionID='MV100362')[0]<br>> rule = conn.SMS_CollectionRuleDirect.new()<br>
> rule.ResourceID = resource<br>> rule.RuleName = 'ResourceID: ' +str(resource)<br>> rule.ResourceClassName = 'SMS_R_System'<br>> coll.AddMembershipRule(rule)<br>><br>> Gives me:<br>><br>
> Traceback (most recent call last):<br>> File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?<br>> coll.AddMembershipRule(rule)<br>> TypeError: __call__() takes exactly 1 argument (2 given)<br>
<br></div></div>Hi, Tim.<br><br>This is one of those ones where I can't easily check my suspicions<br>because I don't have the namespace on my box. I can probably give<br>a hint or two, though. And I'll almost certainly find along the<br>
way that you're doing something no-one's asked the wmi module to<br>do before and which, therefore, I don't support too cleanly!<br><br>No. 1 - get the latest release:<br><br><a href="http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip" target="_blank">http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip</a><br>
<br>which may actually solve the first problem if it's<br>what I think it is, and will certainly help you with<br>the second. If I'm wrong -- and even if I'm right :) --<br>feel free to post back.<br><br>The first one *might* be a symptom of a long-standing bug<br>
I've just squashed which over-cached the WMI methods so<br>that any method call after the first one was attempting<br>to call on the *first* object again.<br><br>The second one is the slight gotcha that -- prior to the<br>
latest release but one -- you had to pass method params<br>as keyword-only. Not helped by the slightly obscure error<br>message which even has me scratching my head when I forget.<br>I've fixed that in the latest release so please run it through<br>
and make sure for me.<br><br>Thanks<br>TJG<br>
<div>
<div></div>
<div>_______________________________________________<br>python-win32 mailing list<br><a href="mailto:python-win32@python.org" target="_blank">python-win32@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>_____________________<br>Ceci n'est pas un email.