WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bettman on April 14, 2016, 10:13:45 AM

Title: WMI Methods
Post by: bettman on April 14, 2016, 10:13:45 AM

Greetings,

Could you briefly outline how to invoke a method from a WMI class? Specifcally I am trying to use the GetKeyProtectorNumericalPassword method of the Win32_EncryptableVolume class to determine what recovery password is for an encrypted OS drive on a workstation
Any help would be appreciated.

Thank you.
Title: Re: WMI Methods
Post by: td on April 14, 2016, 10:55:07 AM
The Tech Database has several sections devoted to WMI.  It is probably the most covered topic in the database.  You might want to try a Tech Database search on the term WMI and scroll down the results for examples that you may find useful. 
Title: Re: WMI Methods
Post by: bettman on April 14, 2016, 10:58:23 AM
I looked at it but I must admit, my understanding of WMI is limited. I couldn't locate anything which describes the calling of a method however.
Title: Re: WMI Methods
Post by: td on April 14, 2016, 11:00:49 AM
Almost every WMI example in the Tech Database calls at least one method.
Title: Re: WMI Methods
Post by: bettman on April 14, 2016, 11:06:38 AM
Could you provide a specific example of one that does?
Title: Re: WMI Methods
Post by: td on April 14, 2016, 11:15:48 AM
Pick almost any WMI example in the Tech Database.
Title: Re: WMI Methods
Post by: bettman on April 14, 2016, 11:19:37 AM
Sorry for asking
Title: Re: WMI Methods
Post by: td on April 14, 2016, 11:31:02 AM
WMI objects, methods and properties are nothing more the COM Automation objects, methods and properties.  If you don't know anything about WinBatch COM Automation support, you should start by reading the COM Help File section of your Consolidated WIL Help file.
Title: Re: WMI Methods
Post by: bettman on April 14, 2016, 11:33:52 AM
All I asked was for a specific example. A simple URL to some sample code would have sufficed
Title: Re: WMI Methods
Post by: td on April 15, 2016, 08:16:32 AM
Quote from: td on April 14, 2016, 02:15:26 PM
Had one of those something-isn't-quite-right-someplace moments.  I believe you are out of luck because the  'KeyProtectorNumericalPassword' method name is 32 characters long so you can't call it from WinBatch directly.  You would have to use something like use CLR hosting and write an  embedded c# script that created a class wrapper that called the actual method that and compile in a WinBatch script.  You could then call the CLR wrapper method from the mainline script.  Ugly at best.

A major, embarrassing  error on my part.  The method name length is not a problem here.  WIL supports COM Automation methods of any name length as long as you can fit the object variable, name and parameters on a single line.  The method name length limit was removed many years ago...

The original post stating otherwise has been removed to hopefully prevent any future confusion on the subject.

Title: Re: WMI Methods
Post by: td on April 15, 2016, 08:27:22 AM
Quote from: bettman on April 14, 2016, 11:33:52 AM
All I asked was for a specific example. A simple URL to some sample code would have sufficed

You asked the identical question about another method on the same WMI class object on  September 10, 2014.  The information provided in the responses can be applied to the 'GetKeyProtectorNumericalPassword' method without to much effort.  The entire topic is still available on this forum, if you don't recall it.