Paul Koning wrote:
> 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)
>
I've never used this particular object, but from general principals try
something like:
opts=tp.Methods_ ("Login").InParameters
opts.Properties_('Username').Value=taskfile.user_name
opts.Properties_('Password').Value=taskfile.password
opts.Properties_('AuthType').Value=1 # CHAP
tp.ExecMethod_('Login',opts)
hth
Roger
_______________________________________________
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32