urgent: needed today!!! WMI child-to-parent

  • Thread starter Thread starter tracernet_v2
  • Start date Start date
T

tracernet_v2

is there a way for us to find the WMI namespace of the given WMI
class...??

its more like, i will be inputting the name of the WMI class and i will
be given the WMI namespace of that class...

any idea how to do this...???
please help...
tnx...
 
Dont know the answer, but it sounds like you should take a look at
reflection in .net and see if yuo can use it to access the
 
Not unless you scan all namespaces available starting from the root.
Note also that classes are namespace scoped so it's possible to have
multiple instances of the same class in different namespaces, so you will
have to scan all namespaces anway.
Following sample (requires V2 of .NET) lists all classes in all namespaces
staring from root, it should be easy to add a search function.


using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Management;
namespace SchemaBrowser
{
public class WmiSchema
{
static void Main() {
WmiSchema ws = new WmiSchema ();
CimNamespaces cns = new CimNamespaces();
foreach(string s in cns)
{
Console.WriteLine(s);
CimClasses ccl = new CimClasses(s) ;
foreach(string sc in ccl)
Console.WriteLine(" " +sc);
}
}
}


class CimClasses : IEnumerable<string>
{
string _cimNamespace;
ManagementObjectSearcher searcher;
public CimClasses(string cimNamespace) {
_cimNamespace = cimNamespace;
EnumerationOptions options = new EnumerationOptions();
options.EnumerateDeep = false;
options.BlockSize = 200;
try
{
searcher = new ManagementObjectSearcher
(new ManagementScope("root\\"+ cimNamespace),
new WqlObjectQuery("select * from meta_class"),
options);
}
finally {searcher.Dispose();}
}
public IEnumerator<string> GetEnumerator()
{
foreach (ManagementClass wmiClass in searcher.Get())
{
yield return wmiClass["__CLASS"].ToString();
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}

class CimNamespaces : IEnumerable<string>
{
public IEnumerator<string> GetEnumerator()
{
// Enumerate all WMI instances of __namespace WMI class.
ManagementClass nsClass = new ManagementClass(
new ManagementScope("root"),
new ManagementPath("__namespace"),
null);

foreach(ManagementObject ns in nsClass.GetInstances())
{
yield return ns["Name"].ToString();
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}


Willy.


| is there a way for us to find the WMI namespace of the given WMI
| class...??
|
| its more like, i will be inputting the name of the WMI class and i will
| be given the WMI namespace of that class...
|
| any idea how to do this...???
| please help...
| tnx...
|
 
John, The OP is looking for a way to search a class in the WMI namespace
schema, reflection isn't of any help here.

Willy.

| Darn - presed the wrong button before I'd finished typing.
|
| As I was saying, I dont kow the answer but you may be able to use
reflection
| in .net to access the WMI types and see if you can enumerate up to the
| namespaces.
|
| Have a read of this for a pointer.
| http://www.ondotnet.com/pub/a/dotnet/2003/10/06/reflectionpt1.html
|
| Regards
|
| John Timney (MVP)
|
| | > Dont know the answer, but it sounds like you should take a look at
| > reflection in .net and see if yuo can use it to access the
| >
| >
| > --
| > --
| > Regards
| >
| > John Timney (MVP)
| > | >> is there a way for us to find the WMI namespace of the given WMI
| >> class...??
| >>
| >> its more like, i will be inputting the name of the WMI class and i will
| >> be given the WMI namespace of that class...
| >>
| >> any idea how to do this...???
| >> please help...
| >> tnx...
| >>
| >
| >
|
|
 
Smart, should do this more often too ;-)

Willy.

| Well, I did caveat myself by saying I didn't know the answer......lol
|
| --
| Regards
|
| John Timney (MVP)
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top