[python-win32] "Property '%s.%s' can not be set" on read/write attribute
Tim Johnson
tojo2000 at gmail.com
Wed Jan 30 10:39:50 CET 2008
YES!!! It works. I was able to successfully run the following version:
###
import wmi
site = 'MV1'
wmi_server = 'mtv-sql-2'
resource = 23012
wmi_namespace = 'root\\sms\\site_%s' % site
conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)
coll = conn.SMS_Collection(CollectionID='MV100362')[0]
rule = conn.SMS_CollectionRuleDirect.new()
rule.ResourceID = resource
rule.RuleName = 'ResourceID: ' + str(resource)
rule.ResourceClassName = 'SMS_R_System'
result = coll.AddMembershipRule(rule)
###
I still get the error on my old code, but maybe mixing
win32com.client-styleobjects 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.
Thanks again, and someday I'll pull a thorn out of your foot or something.
:)
On Jan 30, 2008 1:14 AM, Tim Golden <mail at timgolden.me.uk> wrote:
> Tim Johnson wrote:
> > Hmm, I'm getting a different error now. Could it be having trouble
> passing
> > one wmi object as a parameter to the method of another?
> >
> > import wmi
> > site = 'MV1'
> > wmi_server = 'mtv-sql-2'
> > resource = 23012
> > wmi_namespace = 'root\\sms\\site_%s' % site
> > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)
> > coll = conn.Get('SMS_Collection.CollectionID="MV100362"')
> > rule = conn.Get('SMS_CollectionRuleDirect').SpawnInstance_()
> > rule.ResourceID = resource
> > rule.RuleName = 'ResourceID: ' +str(resource)
> > rule.ResourceClassName = 'SMS_R_System'
> > coll.AddMembershipRule(rule)
> >
> > Gives me :
> >
> > Traceback (most recent call last):
> > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?
> > coll.AddMembershipRule(rule)
> > 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)
> >
> > But this:
> >
> > import wmi
> > site = 'MV1'
> > wmi_server = 'mtv-sql-2'
> > resource = 23012
> > wmi_namespace = 'root\\sms\\site_%s' % site
> > conn = wmi.WMI(computer=wmi_server, namespace=wmi_namespace)
> > coll = conn.SMS_Collection(CollectionID='MV100362')[0]
> > rule = conn.SMS_CollectionRuleDirect.new()
> > rule.ResourceID = resource
> > rule.RuleName = 'ResourceID: ' +str(resource)
> > rule.ResourceClassName = 'SMS_R_System'
> > coll.AddMembershipRule(rule)
> >
> > Gives me:
> >
> > Traceback (most recent call last):
> > File "C:\Users\timjohnson\Desktop\addrule.py", line 16, in ?
> > coll.AddMembershipRule(rule)
> > TypeError: __call__() takes exactly 1 argument (2 given)
>
> Hi, Tim.
>
> This is one of those ones where I can't easily check my suspicions
> because I don't have the namespace on my box. I can probably give
> a hint or two, though. And I'll almost certainly find along the
> way that you're doing something no-one's asked the wmi module to
> do before and which, therefore, I don't support too cleanly!
>
> No. 1 - get the latest release:
>
> http://timgolden.me.uk/python/downloads/wmi-1.3.2.zip
>
> which may actually solve the first problem if it's
> what I think it is, and will certainly help you with
> the second. If I'm wrong -- and even if I'm right :) --
> feel free to post back.
>
> The first one *might* be a symptom of a long-standing bug
> I've just squashed which over-cached the WMI methods so
> that any method call after the first one was attempting
> to call on the *first* object again.
>
> The second one is the slight gotcha that -- prior to the
> latest release but one -- you had to pass method params
> as keyword-only. Not helped by the slightly obscure error
> message which even has me scratching my head when I forget.
> I've fixed that in the latest release so please run it through
> and make sure for me.
>
> Thanks
> TJG
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
--
_____________________
Ceci n'est pas un email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080130/2aa9ae9b/attachment.htm
More information about the python-win32
mailing list