473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get a list of available WMI paths

I would like to display in a listbox all possible paths that can be fed into
the ManagementClass constructor (e.g., Win32_Enviroment,
Win32_OperatingSystem, etc.) Can someone steer me in the direction of how to
generate such a list from within a C# application?
--
Steve
Nov 17 '05 #1
3 4379

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I would like to display in a listbox all possible paths that can be fed
into
the ManagementClass constructor (e.g., Win32_Enviroment,
Win32_OperatingSystem, etc.) Can someone steer me in the direction of how
to
generate such a list from within a C# application?
--
Steve


This should dump all local root namespaces classes:

string cimRoot = "root\\";
ManagementClass nsClass = new ManagementClass(
new ManagementScope(@"root"),
new ManagementPath("__namespace"),
null);
foreach(ManagementObject ns in nsClass.GetInstances()) {
Console.WriteLine(cimRoot + ns["Name"].ToString());
ManagementClass newClass = new ManagementClass(cimRoot +
ns["Name"].ToString());
EnumerationOptions options = new EnumerationOptions();
options.EnumerateDeep = true; // set to false if only the root
classes are needed
ManagementObjectCollection moc = newClass.GetSubclasses(options);
foreach(ManagementObject o in moc) {
if(o["__SuperClass"] == null)
Console.WriteLine(o["__Class"]);
else
Console.WriteLine("\t" + o["__Class"]);
}
}
}

Willy.


Nov 17 '05 #2
This is exactly what I was hoping to find. I've tested your code and it
works great in the environment I am coding. I'm trying now to understand
what you did. Thanks very much!

"Willy Denoyette [MVP]" wrote:

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I would like to display in a listbox all possible paths that can be fed
into
the ManagementClass constructor (e.g., Win32_Enviroment,
Win32_OperatingSystem, etc.) Can someone steer me in the direction of how
to
generate such a list from within a C# application?
--
Steve


This should dump all local root namespaces classes:

string cimRoot = "root\\";
ManagementClass nsClass = new ManagementClass(
new ManagementScope(@"root"),
new ManagementPath("__namespace"),
null);
foreach(ManagementObject ns in nsClass.GetInstances()) {
Console.WriteLine(cimRoot + ns["Name"].ToString());
ManagementClass newClass = new ManagementClass(cimRoot +
ns["Name"].ToString());
EnumerationOptions options = new EnumerationOptions();
options.EnumerateDeep = true; // set to false if only the root
classes are needed
ManagementObjectCollection moc = newClass.GetSubclasses(options);
foreach(ManagementObject o in moc) {
if(o["__SuperClass"] == null)
Console.WriteLine(o["__Class"]);
else
Console.WriteLine("\t" + o["__Class"]);
}
}
}

Willy.


Nov 17 '05 #3
I've incorporated the code into my solution with a few minor changes. It
works just as I was hoping it would. I'm now looking over the code to better
understand what you did. Thanks.

"Willy Denoyette [MVP]" wrote:

"Steve Teeples" <St**********@discussions.microsoft.com> wrote in message
news:B1**********************************@microsof t.com...
I would like to display in a listbox all possible paths that can be fed
into
the ManagementClass constructor (e.g., Win32_Enviroment,
Win32_OperatingSystem, etc.) Can someone steer me in the direction of how
to
generate such a list from within a C# application?
--
Steve


This should dump all local root namespaces classes:

string cimRoot = "root\\";
ManagementClass nsClass = new ManagementClass(
new ManagementScope(@"root"),
new ManagementPath("__namespace"),
null);
foreach(ManagementObject ns in nsClass.GetInstances()) {
Console.WriteLine(cimRoot + ns["Name"].ToString());
ManagementClass newClass = new ManagementClass(cimRoot +
ns["Name"].ToString());
EnumerationOptions options = new EnumerationOptions();
options.EnumerateDeep = true; // set to false if only the root
classes are needed
ManagementObjectCollection moc = newClass.GetSubclasses(options);
foreach(ManagementObject o in moc) {
if(o["__SuperClass"] == null)
Console.WriteLine(o["__Class"]);
else
Console.WriteLine("\t" + o["__Class"]);
}
}
}

Willy.


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jnc | last post by:
Hi, I was wondering if anybody had any pointers on the following: I need to write some code which takes a list of file paths and transforms them into a treeview which shows the directory...
1
by: John | last post by:
Hi, we have the following problem: in our application v1.0 we have static html pages (+ some javascript). With a CMS (a Content Management System) some "mortal" people can add or expand the...
3
by: Bryan | last post by:
This is for a utility that I am writing to update all of our Excel reports. I currently have a form with a couple list boxes and browse buttons. One browse button allows the user to add the XLS...
4
by: James Kunicki | last post by:
Hello, I would like to know if anyone as found a way to list a image next to a list box to indicate what type of drive (local or network) and a folder I would like to present in a user...
3
by: sva | last post by:
Using C# for an application in which I am working on, I need to display the available shared folders on the computer that's running the application. The shared folder paths need to be in UNC format...
2
by: dave6502 | last post by:
Struggling newbe here, some of my #includes work, some dont. Is it possible to list the include path ? (in BASH), I have looked at the environmental variables (loads of them) but cannot find a...
5
by: antar2 | last post by:
Hello, I would like to read and print files, of which the complete filepaths are mentioned in another textfile. In this textfile (list.txt) are for example the following paths: ...
1
by: latalui | last post by:
how write a code to find all the shortest paths available in a graph with weight corresponding to it. i shall be to thankful to u if anyone post me as soon as possible.
0
by: drewgy | last post by:
Can anyone tell me how to get a list of full UNC paths for all printers on a network? I have tried using WMI but the following code only gives me a list of local printers, and doesn't give me the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.