Wmic.exe

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Wmic.exe

#16 Post by Compo » 23 Feb 2022 05:53

atfon wrote:
22 Feb 2022 13:05
I doubt I have to tell most of you on this forurm, but for those who might not be aware, you can get a list of WMI aliases Friendly Name and Corresponding full name with this command:

Code: Select all

wmic alias list brief
Whilst that may be useful to some, it doesn't really provide all of the information needed to translate one methodology to another.

It provides the FriendlyName and Target, which is great, however there is still more information needed, and that is the NameSpace...

Let's take an example: the FriendlyName alias itself, when run from the default namespace ROOT\CIMV2, i.e.

Code: Select all

wmic alias list brief
still produces output, as you've seen, but in order to do that it also needs to, behind the scenes, switch to the appropriate namespace, ROOT\CLI

To find out that namespace you could probably currently do it like this:

Code: Select all

%SystemRoot%\System32\wbem\WMIC.exe alias WHERE FriendlyName="alias" GET /Value 2>NUL | %SystemRoot%\System32\findstr.exe "^FriendlyName= ^NameSpace= ^Target="

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Wmic.exe

#17 Post by Aacini » 23 Feb 2022 14:28

Wow! A lot of new things here!

[BRIEF OFF-TOPIC INTRO]: I don't like large systems with huge documentation... When I learned IBM-1130 assembly language and OS functions in 1977, I could read the extensive documentation and found things! When I started to write programs for the (new) IBM-PC around 1981 I could read the books and manuals and found the things I wanted, and the same happened with a lot of products of that era, like all Turbo-languages (TASM, Pascal, C), dBase IV, Clipper, FrameWork and a long et cetera... I am not talking about I knew all possible features of all such products, but that when I had a problem I read the manuals and solved it!

The world changed for me in this respect when I started to study the Windows-32 API. It was/is very, very hard to find the things I wanted from the Win32-API documentation. Note that I am not talking about the huge amount of information that these products have, but about the frequently very poor ("incoherent") way to organize such information when it is presented to the user. When I have a problem, I frequently have not idea on which part of the API documentation I must search looking for such a feature. I must review several (frequently many) sections and review a very large amount of (non related) information until I found what I was looking for. It seems that the way to learn to use certain modern systems was designed with the purpose of be intrinsically difficult...

The Windows Management Instrumentation (WMI) is another product of such a type. It have a few NameSpaces, many Classes in each NameSpace, and a ton of Properties in each Class. If you want to get a certain data, which NameSpace/Class/Property gives such information? There is no easy way to know it. You need to review many, many properties until find the required one!

As I said, I hate large systems with bad documentation... [END OF INTRO]
Compo wrote:
23 Feb 2022 05:53
atfon wrote:
22 Feb 2022 13:05
I doubt I have to tell most of you on this forurm, but for those who might not be aware, you can get a list of WMI aliases Friendly Name and Corresponding full name with this command:

Code: Select all

wmic alias list brief
Whilst that may be useful to some, it doesn't really provide all of the information needed to translate one methodology to another.

It provides the FriendlyName and Target, which is great, however there is still more information needed, and that is the NameSpace...

Let's take an example: the FriendlyName alias itself, when run from the default namespace ROOT\CIMV2, i.e.

Code: Select all

wmic alias list brief
still produces output, as you've seen, but in order to do that it also needs to, behind the scenes, switch to the appropriate namespace, ROOT\CLI

To find out that namespace you could probably currently do it like this:

Code: Select all

%SystemRoot%\System32\wbem\WMIC.exe alias WHERE FriendlyName="alias" GET /Value 2>NUL | %SystemRoot%\System32\findstr.exe "^FriendlyName= ^NameSpace= ^Target="
After read this information, I did several tests until I completed this program that I called wmicAlias.bat:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

rem wmicAlias.bat: List the data of "alias" Alias from wmic.exe
rem Antonio Perez Ayala

for /F "tokens=1* delims==" %%a in (
    'WMIC.exe alias GET /Value ^| findstr.exe "^Description= ^FriendlyName= ^Target= ^NameSpace="') do (
   if "%%a" equ "Description" (
      set "Description=%%b"
   ) else (
      if defined Description (
         echo/
         for /F "delims=." %%c in ("!Description!") do echo Description=%%c.
         set "Description="
      )
      set "%%a=%%b"
      echo %%a=!%%a:~0,-1!
   )
)
I run this program to get a list of WMIC.exe "Alias" (wmicAlias.txt); this is a part of such output:

Code: Select all


Description=Network adapter management.
FriendlyName=NICConfig
Target=Select * from Win32_NetworkAdapterConfiguration
NameSpace=ROOT\CIMV2

Description=Management of the system driver for a base service.
FriendlyName=SysDriver
Target=Select * from Win32_SystemDriver
NameSpace=ROOT\CIMV2

Description=Tape drive management.
FriendlyName=TapeDrive
Target=Select * from Win32_TapeDrive
NameSpace=ROOT\CIMV2

. . . . .

Description=This provides access to the aliases available on the local system.
FriendlyName=Alias
Target=Select * from Msft_CliAlias
NameSpace=ROOT\cli

. . . . .
After that, I wanted to modify wmiClass.bat program in order to get classes from a given NameSpace. The modification was pretty simple thanks to JScript's "Arguments.Named" feature:

Code: Select all

@if (@CodeSegment == @Batch) @then


@echo off

if "%~1" neq "/?" CScript //nologo //E:JScript "%~F0" %* & goto :EOF

echo Show properties of a WMI class (via a JScript collection)
rem  Antonio Perez Ayala
rem  - 2022/02/21: version 1
rem  - 2022/02/23: version 1.1: /NS option added
echo/
echo    wmiClass [/NS:namespace] [class [prop1 prop2 ...]]
echo/
echo If no class is given, show the names of all WMI classes.
echo/
echo If just the class is given, show the names of all its properties.
echo/
echo If a list of properties is given, show their values. For example:
echo    wmiClass Win32_LocalTime Year Month Day Hour Minute Second
echo/
echo If /NS option is given, specify the NameSpace (default: \root\cimv2):
echo    wmiClass /NS:\root\cli MSFT_CliAlias
goto :EOF


@end


// http://msdn.microsoft.com/en-us/library/aa393741(v=vs.85).aspx
var args = WScript.Arguments.Unnamed,
    options = WScript.Arguments.Named,
    colItems;
if ( args.length > 1 ) {  // Show values of given properties
   // http://msdn.microsoft.com/en-us/library/windows/desktop/aa394606(v=vs.85).aspx
   colItems = GetObject("WinMgmts:"+(options.Exists("NS")?options.Item("NS"):"")).ExecQuery("Select * from " + args.Item(0));
   for ( var e = new Enumerator(colItems); ! e.atEnd(); e.moveNext() ) {
      for ( var i = 1; i < args.length; i++ ) {
         WScript.Stdout.WriteLine(args.Item(i)+"="+eval("e.item()."+args.Item(i)));
      }
   }
} else if ( args.length == 1 ) {  // Show all properties of given class
   // Method suggested by: http://msdn.microsoft.com/en-us/library/aa392315(v=vs.85).aspx
   //                      https://gallery.technet.microsoft.com/f0666124-3b67-4254-8ff1-3b75ae15776d
   colItems = GetObject("WinMgmts:"+(options.Exists("NS")?options.Item("NS"):"")).Get(args.Item(0)).Properties_;
   for ( var e = new Enumerator(colItems); ! e.atEnd(); e.moveNext() ) {
      WScript.Stdout.WriteLine(e.item().Name);
   }
} else {  // Show all classes
   // https://gallery.technet.microsoft.com/scriptcenter/5649568b-074e-4f5d-be52-e8b7d8fe4517
   colItems = GetObject("WinMgmts:"+(options.Exists("NS")?options.Item("NS"):""));  // if no NameSpace given, imply ("WinMgmts:\root\cimv2")
   for ( var e = new Enumerator(colItems.SubclassesOf()); ! e.atEnd(); e.moveNext() ) {
      WScript.Stdout.WriteLine(e.item().Path_.Class);
   }
}
After that, I wanted to test the new /NS option, so I reviewed the wmicAlias.txt list looking for a NameSpace other than ROOT\CIMV2 and this is the first one I found:

Code: Select all

Description=Remote Desktop NIC management.
FriendlyName=RDNIC
Target=Select * from Win32_TSNetworkAdapterSetting
NameSpace=ROOT\CIMV2\TerminalServices
... so I did this test:

Code: Select all

wmiClass /NS:ROOT\CIMV2\TerminalServices Win32_TSNetworkAdapterSetting
C:\Users\Antonio\Documents\Test\FindRepl\wmiClass.bat(45, 4) (null): 0x8004100E
What happened? This error indicate that such "ROOT\CIMV2\TerminalServices" NameSpace does not exists! (and remembers me that I should add some error detection code that show informative messages)

After guessing what is happening here, I concluded that "ROOT\CIMV2\TerminalServices" could not be a NameSpace! Perhaps the NameSpace is the usual ROOT\CIMV2 and the class is TerminalServices\Win32_TSNetworkAdapterSetting, but this don't works. I tried all possible combinations of "ROOT\CIMV2", "TerminalServices" and "Win32_TSNetworkAdapterSetting" as NameSpace/Class/Property but it don't works either. This means that when wmic.exe gets the RDNIC Alias (FriendlyName), it process such a name in a way that is not the standard (documented?) way! (at least, not with the WMI knowledge I have so far)

[This is very frustrating but, want you know what is even worst? The future reply of someone expert in WMI that will say: "Of course! You just need to put the X part in Y site! Isn't it obvious?" I hate WMI and wmic.exe...]

Ok. Anyway, I did several tests including /NS:ROOT\CIMV2 option and it seems to work correctly. Then, I look for another NameSpace different than ROOT\CIMV2 and ROOT\CIMV2\TerminalServices in wmicAlias.txt list and found the only one:

Code: Select all

Description=This provides access to the aliases available on the local system.
FriendlyName=Alias
Target=Select * from Msft_CliAlias
NameSpace=ROOT\cli
... so I did this test:

Code: Select all

wmiClass /NS:ROOT\cli Msft_CliAlias

Connection
Description
Formats
FriendlyName
PWhere
Qualifiers
Target
Verbs
Excellent! This means that the new /NS option works correctly...

I extended previous test and run this:

Code: Select all

wmiClass /NS:ROOT\cli Msft_CliAlias Connection Description Formats FriendlyName PWhere Qualifiers Target Verbs > wmiAliasClass.txt
... so I get a file with alias listing similar to the previous wmicAlias.txt one, but this time generated without the aid of wmic.exe!

This is the segment of such a file that corresponds to OS alias:

Code: Select all

Connection=
Description=Installed Operating System/s management. 
Formats=
FriendlyName=OS
PWhere=
Qualifiers=null
Target=Select * from Win32_OperatingSystem
Verbs=
After that, I devised a new /A:alias wmiClass.bat option that get a wmic.exe alias (like "OS") and retrieve the corresponding class via "/NS:ROOT\cli Msft_CliAlias FriendlyName Target" properties. This feature will allow us to get WMI values using the same names of wmic.exe; for example:

Code: Select all

wmiClass /A:OS LocalDateTime
I am working on such new version now...

Antonio

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Wmic.exe

#18 Post by atfon » 23 Feb 2022 14:45

Very nice! Thank you, Antonio.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Wmic.exe

#19 Post by Compo » 23 Feb 2022 14:50

Too much to <QUOTE />/<SNIP /> out, so just to say that I'm glad my information/prompt has assisted you in improving your alternative solution Antonio.

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: Wmic.exe

#20 Post by atfon » 23 Feb 2022 15:11

FWIW, I find this site to be helpful for just browsing the available WMI namespaces, classes, etc.

https://wutils.com/wmi/

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Wmic.exe

#21 Post by Aacini » 23 Feb 2022 17:39

atfon wrote:
23 Feb 2022 15:11
FWIW, I find this site to be helpful for just browsing the available WMI namespaces, classes, etc.

https://wutils.com/wmi/
Wow! This is worst that I thought!

There are 142 NameSpaces and 23896 Classes in such a site! How many Properties do you think are defined there? Close to one million? :shock:

In which NameSpace/Class/Property there is the information you need? :o

On the other hand, it's just absurd that a lot of people had invested too much time in the creation of such amount of Properties, but we used this technology just to get the date and time... :cry:

Antonio

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: Wmic.exe

#22 Post by siberia-man » 24 Feb 2022 19:12

I decided add my 5 cents to this topic. There is the next version of wmiClass hybrid. I took the version 1.1 by Aacini and performed the following changes:
- Rethink usage and rewrite the code significantly
- Add examples into the help message
- Add /where, the new option for limiting the number of records

Code: Select all

0</*! ::

:::SYNOPSIS
:::    wmiClass [/ns:Namespace] [*|class [/where:WhereClause] [*|property ...]]
:::
:::DESCRIPTION
:::  Show properties of a WMI class
:::
:::ARGUMENTS
:::    /ns:Namespace       specify the namespace (defaults to \root\cimv2)
:::    /where:WhereClause  clause to restict records
:::    class               show the properties of the given class
:::    class property      show the value of the property of the given class
:::
:::EXAMPLES
:::  List names of all WMI classes
:::    wmiClass *
:::
:::  List all properties for the given class
:::    wmiClass Win32_LocalTime
:::
:::  Show all values
:::    wmiClass Win32_LocalTime *
:::
:::  Show the specific values
:::    wmiClass Win32_LocalTime Year Month Day
:::
:::  Filter records and show the specific values
:::    wmiClass Win32_Process ProcessID Name /where:"Name = 'cmd.exe'"

::History
::  2022/02/25: Version 1.2
::  https://www.dostips.com/forum/viewtopic.php?p=66294#p66294
::  https://github.com/ildar-shaimordanov/cmd.scripts/blob/master/wmiClass.bat
::  - Rethink usage and rewrite the code significantly
::  - Add examples into the help message
::  - Add /where, the new option for limiting the number of records
::
::  Based on Version 1.1 by Antonio Perez Ayala
::  https://www.dostips.com/forum/viewtopic.php?p=66284#p66284

@echo off

if "%~1" == "" (
	findstr "^:::" "%~f0"
	goto :EOF
)

cscript //nologo //e:javascript "%~f0" %*
goto :EOF
*/0;

var args = WScript.Arguments.Unnamed;
var opts = WScript.Arguments.Named;

var className = args.length ? args.item(0) : '*';

var propNames = [];
for (var i = 1; i < args.length; i++) {
	propNames.push(args.Item(i));
}

var ns = opts.Exists('NS') ? opts.Item('NS') : '';

var wmi = GetObject('WinMgmts:' + ns);

var collection;
var fetch;

function enumerate(collection, fetch) {
	var r = [];
	for (var e = new Enumerator(collection); ! e.atEnd(); e.moveNext()) {
		r.push(fetch(e.item()));
	}
	return r;
}

if ( className == '*' ) {
	collection = wmi.SubclassesOf();
	fetch = function(el) {
		return el.Path_.Class;
	};
} else if ( propNames.length == 0 ) {
	collection = wmi.Get(className).Properties_;
	fetch = function(el) {
		return el.Name;
	};
} else {
	var whereClause = opts.Exists('WHERE') ? ' where ' + opts.Item('WHERE') : '';

	collection = wmi.ExecQuery('select * from ' + className + whereClause);
	fetch = function(el) {
		if ( propNames.length == 1 && propNames[0] == '*' ) {
			propNames = enumerate(el.Properties_, function(el) {
				return el.Name;
			});
		}

		var r = [];
		for (var i = 0; i < propNames.length; i++) {
			var n = propNames[i];
			r.push(n + "=" + el[n]);
		}
		return r.join('\n');
	}
}

WScript.StdOut.WriteLine(enumerate(collection, fetch).join('\n'));

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Wmic.exe

#23 Post by Aacini » 27 Feb 2022 01:33

siberia-man wrote:
24 Feb 2022 19:12
I decided add my 5 cents to this topic. There is the next version of wmiClass hybrid. I took the version 1.1 by Aacini and performed the following changes:
- Rethink usage and rewrite the code significantly
- Add examples into the help message
- Add /where, the new option for limiting the number of records

Code: Select all

. . . . .
Fantastic! :)

I like the "*" parameter, the /WHERE option and the extended help, but I don't like the ancient use of double-colons to insert comments in a Batch-file, nor the triple-colon for help texts. I formatted the help screen to the usual DOS style and devised a new way to insert large help texts in a much clearer way... This is a new feature!!!

I also like very much the clever use of functions and methods that process data aggregates as a unit. This is more efficient than my old style of for loops processing elements one-by-one, although it was somewhat confusing that you first define a function in a variable that will be executed later. I adopted your code and adjusted a few somewhat disordered sections (like the nested definition of function(el) inside the definition of another function(el) for fetch), so it looks more coherent now...

Code: Select all

@if (@CodeSegment == @Batch) ( @then

Show properties of a WMI class.

wmiClass [/NS:namespace] [*|class [*|property ...] [/WHERE:clause]]

  /NS:namespace     Specify the namespace, defaults to \root\cimv2.
  class             Show property names of the given class.
  class property    Show values of given properties of the class or alias.
  /WHERE:clause     Clause to select property records to process.

List names of all WMI classes
   wmiClass *

List all properties of the given class
   wmiClass Win32_LocalTime

Show values of all properties of the class
   wmiClass Win32_LocalTime *

Show specific values
   wmiClass Win32_LocalTime Year Month Day

Show values from a wmic.exe alias
   wmiClass OS LocalDateTime

Show selected records
   wmiClass Win32_Process ProcessID Name /where:"Name='cmd.exe'"

@endHelp

Developed and written by Antonio Perez Ayala

First version of this program is a modification of wmiCollection function
included in FindRepl.bat version 2.2 program released on 2014
https://www.dostips.com/forum/viewtopic.php?f=3&t=4697&p=38121#p38121

- 2022/02/21: version 1
- 2022/02/23: version 1.1: /NS option added
- 2022/02/27: version 1.3: significant code rewrite based on version 1.2 written by siberia-man
                           https://www.dostips.com/forum/viewtopic.php?p=66294#p66294
                           "*" and /WHERE options added. Auto-search for alias added
)

@echo off

if "%~1" == "" (
   for /F "skip=2 tokens=1* delims=:" %%a in ('findstr /N "^" "%~F0"') do (
      if "%%b" == "@endHelp" goto :EOF
      echo/%%b
   )
)

CScript //nologo //E:JScript "%~F0" %*
goto :EOF


@end


// http://msdn.microsoft.com/en-us/library/aa393741(v=vs.85).aspx

var args = WScript.Arguments.Unnamed,
    opts = WScript.Arguments.Named,
    wmi  = GetObject( "WinMgmts:" + (opts.Exists("NS")?opts.Item("NS"):"") ),
    clas = args.Item(0),  collection, fetch;

function enumerate (collection,fetch) {
    var r = [];
    for ( var e = new Enumerator(collection); !e.atEnd(); e.moveNext() ) {
        r.push(fetch(e.item()));
    }
    return r;
}


if ( clas == "*" ) {  // List all classes in this NameSpace; ignore properties, if any
   collection = wmi.SubclassesOf();
   fetch = function(el) { return el.Path_.Class; };

} else if ( args.length == 1 ) {  // No properties given: list all property names of given class
   collection = wmi.Get(clas).Properties_;
   fetch = function(el) { return el.Name; };

} else {  // Show property values
   var where = opts.Exists('WHERE') ? " where "+opts.Item('WHERE') : "";
   collection = wmi.ExecQuery( "Select * from " + clas + where );

   if ( (new Enumerator(collection)).atEnd() ) {  // No class found: check the alias
      var alias = GetObject( "WinMgmts:\\root\\cli" );
      collection = alias.ExecQuery("Select Target from Msft_CliAlias where FriendlyName='"+clas+"'");
      var e = new Enumerator(collection);
      if ( e.atEnd() ) {
         WScript.Stderr.WriteLine("Class or alias not exists: "+clas);
         WScript.Quit(1);
      }
      clas = e.item().Target.substr(14);
      collection = wmi.ExecQuery( "Select * from " + clas + where );
   }

   var prop = [];
   if ( args.Item(1) == "*" ) {  // Show all properties of this class; ignore rest, if any
      prop = enumerate( wmi.Get(clas).Properties_, function(el) { return el.Name; } );
   } else {  // Show given properties
      for ( var i = 1; i < args.length; i++ ) { prop.push(args.Item(i)); }
   }

   fetch = function(el) {
              var r = [];
              for ( var i = 0; i < prop.length; i++ ) {
                 var n = prop[i];
                 r.push(n + "=" + el[n]);
              }
              return r.join('\n');
           }
   ;

}

WScript.StdOut.WriteLine(enumerate(collection,fetch).join('\n'));
EDIT 2022/03/01: I completed a couple minor changes in the code, cosmetic changes mainly...

The new wmiClass.bat version 1.3 include the "*" parameter and the /WHERE clause as defined by siberia-man. I also added the capability of search for a WMIC Alias if the class was not found when values of properties were requested; this feature allows to search for anyone of the (unknow) real class names or the (usual) wmic.exe alias. For example, both commands below returns the same result:

Code: Select all

wmiClass.bat Win32_OperatingSystem LocalDateTime
LocalDateTime=20220227011806.768000-360

wmiClass.bat OS LocalDateTime
LocalDateTime=20220227011813.174000-360
Antonio

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: Wmic.exe

#24 Post by siberia-man » 27 Feb 2022 09:16

Aacini wrote:
27 Feb 2022 01:33
... the ancient use of double-colons to insert comments in a Batch-file, nor the triple-colon for help texts
I didn't realized why double-, triple- or any-colons are of old-fashioned style except error raising within blocks.

Honestly, I don't like any existing option used (by me or others) for putting help within batch scripts and displaying it on demand. Unix shells are better with their cat heredoc.

Your current suggestion looks much better but it has a small weakness because it relies on the unreliable number of leading lines supposed to be skipped.

The modifications you introduced are definitely good. If you don't mind, I'd like to use them in my version of the script when I continue working on it.

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Wmic.exe

#25 Post by Aacini » 27 Feb 2022 22:49

siberia-man wrote:
27 Feb 2022 09:16

...

The modifications you introduced are definitely good. If you don't mind, I'd like to use them in my version of the script when I continue working on it.
Of course you can! :D


Is there any way to change these code segments:

Code: Select all

// List all classes in this NameSpace
collection = wmi.SubclassesOf();
fetch = function(el) { return el.Path_.Class; };


// List all property names of given class
collection = wmi.Get(clas).Properties_;
fetch = function(el) { return el.Name; };
by a request of this type?

Code: Select all

collection = wmi.ExecQuery( "Select * from " + clas );
fetch = function(el) { return     WHAT?
If so, the capabilities of wmiClass.bat program could be augmented in a simple way...

Antonio

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: Wmic.exe

#26 Post by siberia-man » 28 Feb 2022 20:11

Aacini wrote:
27 Feb 2022 22:49
Is there any way to change these code segments:
I can see that you changed the code to enable wmi aliases and you invoke new Enumerator twice simply just to check if it's class itself or its alias. It's not optimal for now.

I am not 100% sure that understand exactly what you want. Do you mean to adapt the functions enumerate and fetch for the results of wmi.ExecQuery?

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Wmic.exe

#27 Post by Aacini » 01 Mar 2022 14:30

siberia-man,

Yes. I want to solve two problems with a single solution. Let's me explain:

In this section:

Code: Select all

if ( clas == "*" ) {  // List all classes in this NameSpace; ignore properties, if any
   collection = wmi.SubclassesOf();
   fetch = function(el) { return el.Path_.Class; };
... the displayed classes are always all of them. If we could complete the same request via:

Code: Select all

   collection = wmi.ExecQuery ( "Select * from " + I don't know what about(clas) ...
... then we could include a WhereClause to select the displayed classes.

The same point apply to this section:

Code: Select all

} else if ( args.length == 1 ) {  // No properties given: list all property names of given class
   collection = wmi.Get(clas).Properties_;
   fetch = function(el) { return el.Name; 
But in this last case we also could test if the class not exists and then seek for the equivalent wmic.exe Alias using Target and taking the FriendlyName=class (in \root\cli namespace and Msft_CliAlias class). The collection = wmi.Get(clas).Properties_; line mark an error if the class doesn't exists and there is not any way to avoid such an error. However, the collection = wmi.ExecQuery( "Select * from " + clas + where ); does NOT cause an error if the class not exists, it just returns an empty collection that can be tested via the (new Enumerator(collection)).atEnd() method (unless there is a better way to do this).

So, if is there a way to replace such lines via ExecQuery equivalents, I could implement these two features in a very simple way.

Antonio

Post Reply