[wpkg-users] RFC: WMI checks

Malte Starostik lists at malte.homeip.net
Wed Oct 10 11:42:36 CEST 2012


Hello Rainer,

Am Mittwoch, 10. Oktober 2012, 08:29:31 schrieb Rainer Meier:
> > <check type="wmi" condition="exists"
> > path="Win32_QuickFixEngineering.HotFixID='KB976902',ServicePackInEffect=''
> > "/>
> > 
> > One obvious enhancement would be to a "condition" that allows for "path"
> > to
> > contain a complete WQL query. But before considering this further and what
> > combinations of condition/path/value would make sense, I'd like to check
> > if
> > there is any interest in this at all and if it has a chance to make it
> > into WPKG.
> > 
> > I'm aware that execute checks with wmic or custom scripts can be used
> > here, but such an approach would come with a very high performance
> > penalty when it's trivial to run the check right from WPKG.
> 
> Actually the idea is good from my point of view. Especially since WPKG
> already has implemented some code to query WMI, so this code could be
> re-used. Although I think the number of users of such "wmi" type checks
> will be pretty small I think it could be a valuable new feature. I think it
> would make sense to support full WMI queries in path expression only and
> perhaps collect a couple of "nice to know" samples on WPKG wiki.
> Certainly it could make sense to support also "equals" condition or similar
> to compare the results to a regular expression in "value" attribute.

Yes, thought about this and I guess that would be a very powerful feature.  
/Maybe/ I'll come up with more about this around the weekend.
 
> I am currently quite loaded with other tasks but I will definitely return
> and add some improvements. If you have some working sample code you can
> probably send it to me. Else I will very likely think about an
> implementation myself.

The part that makes the above example work is actually just a trivial 
additional block in checkCondition():

// Check type: wmi
case "wmi":
        if (checkCond == null) {
                dinfo("No execute condition specified, assuming 'exists'.");
                checkCond = "exists";
        }
        switch (checkCond) {
        case "exists":
                try {
                        returnValue = GetObject("winmgmts://./root/cimv2:" + 
checkPathExpanded) !== null;
                        dinfo("WMI existance check for " + checkPathExpanded + 
" returned " + returnValue);
                }
                catch (e) {
                        dinfo("WMI existance check for " + checkPathExpanded + 
" failed: " + e.description);
                        returnValue = false;
                }
                break;

        default:
                throw new Error("Check condition " + checkCond + " unknown for 
type wmi.");
                break;
        }
        break;


> I think the code should be kept as small as possible and only cover basic
> use-cases. For more complex operations it's likely still more advisable to
> use exec style checks and write some decent script which handles WMI query,
> error handling, parsing and return values.

Totally agree.

Kind regards,
Malte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wpkg.org/pipermail/wpkg-users/attachments/20121010/5ad2cfd5/attachment-0002.html>


More information about the wpkg-users mailing list