[python-win32] Setting object values that are an object (win32com)

sangeetha sangeethak at amiindia.co.in
Thu Nov 10 11:40:22 CET 2011



Paul Koning <pkoning <at> equallogic.com> writes:
 
 I'm using win32com.client to access WMI (via SWbemServices).  Much of
 it works -- very nice.
 
 There are two things I'm trying to do that I can't get to work right.
 Or rather, two approaches to the same thing, neither of which work.  I
 tried to dig through Microsoft docs to figure this out, but that
 didn't help.
 
 I'm dealing with a class (MSiSCSIInitiator_TargetClass).  I have an
 instance of that class (output of an InstancesOf call in
 SWbemServices).  According to the class definition -- and a browser I
 have agrees -- that class has a LoginOptions property, of type
 MSiSCSIInitiator_TargetLoginOptions. 
 
 In theory, I can set that property and then call the Login method of
 the Target class, or I can pass a LoginOptions argument into the
 Target.Login method instead.
 
 I tried both.
 
 1. I assume that what I have to do is create an instance of the
 TargetLoginOptions class, fill that in, then set the LoginOptions
 attribute of the Target class to what I just created:
 
                 C = wmi.Get ("MSiSCSIInitiator_TargetLoginOptions")
                 opts = C.SpawnInstance_ ()
                 opts.Username = taskfile.user_name
                 opts.Password = taskfile.password
                 opts.AuthType = 1  # CHAP
                 tp.LoginOptions = opts
                 tp.Login ()
 
 I get a "generic error".  From the behavior of the rest of the system,
 it looks like the operation is attempted, but the outcome is as if the
 LoginOptions had not been present.
 
 2. Since the Login method has a set of inputs, one of which is
 LoginOptions, I tried passing "opts" that way.
 
 The intuitively obvious syntax is:
 		tp.Login (LoginOptions = opts)
 but that doesn't work.  It looks like method invocation knows about
 positional arguments but not keyword arguments.
 
So I read an MSDN article that talks about constructing input
 arguments.  It translates to this:
 
                 ip = wmi.Get ("MSiSCSIInitiator_TargetClass"). \
                      Methods_ ("Login").inParameters.SpawnInstance_()
                 ip.LoginOptions = opts
                 tp.Login (ip)

 Same result: no luck (operation is attempted but it acts as if
 LoginOptions was not present.
 
 I also tried changing the last line to:
 	        tp.ExecMethod_ ("Login", ip)
 
 Almost the same result -- a "Generic Failure" exception, but this time
 it appears that the operation was not actually attempted.
 
 Does anyone have any idea where I can go from here?
 
      paul
 


Dear paul,

Am also facing the same problem , hope u would have find the solution for this
by now .please help me in giving the inputs for the
MSiSCSIInitiator_TargetLoginOptions which has to be passed as the input for the
MSiSCSIInitiator_Target Class .

i couldn't set the chap username and password for logging in the target .please
help me 

-

Thanks
Sangeetha 






More information about the python-win32 mailing list