C# – Querying machine specs

c++wmi

What are some ways that I can query the local machine's specifications (a range of things from CPU specs, OS version, graphics card specs and drivers, etc.) through a programmatic interface? We're writing a simple app in C# to test compatibility of our main app and want to have it dump out some system metrics, but I can't seem to find where to even start, what interfaces to use, libraries, anything.

I've tried all kinds of searches, but can only find programs, and GUI ones at that, which require a user to interact with, or have to install.

Alternatively, a small, command-line program would work just as well, as long as we'd be permitted to distribute it with the test app.

I have found one program that gets some of the specs I'd want, PsInfo. However, it seems to require each user to agree to some license when it is first run, even though it's a command line app. Plus, it only deals with OS/CPU info, and I will need more than that.

Also: forgot to mention explicitly, but this indeed is only going to be necessary for Windows machines. You folks are quick!

Edit: This WMI does look like what I need, thanks! Quite a can of worms though, so I've got to dive in. It mentions that for some things the user has to have administrator privileges; this probably won't be a big problem, but it might limit it a little.

Best Solution

For this type of information WMI is your friend. Fortunately dealing with WMI in .NET is much easier than in the unmanaged world. There are quite a lot of articles out there to get started with, like this one, or this one to retrieve processor information.

You will end up writing SQL-like queries against objects in the WMI namespace to retrieve the information you want.

Related Question