Request Machine Specifications

How can I request local machine specifications (a number of things from the processor specification, OS version, graphics card and driver specifications, etc.) through the program interface? We are writing a simple application in C # to check the compatibility of our main application and we want it to display some system indicators, but I can’t find where to even start, which interfaces to use, libraries, whatever.

I tried all kinds of searches, but I can only find programs and graphical interfaces that require user interaction or installation.

In addition, a small command-line program will work just as well if we are allowed to distribute it using a test application.

I found one program that gets some of the specifications I need, PsInfo . However, apparently, each user should agree to some kind of license at the first start, although this is a command line application. Also, it deals only with OS / CPU information, and I need more.

Also: forgot to mention explicitly, but it really will be necessary for Windows machines. You guys are fast!

Edit: This WMI really looks like what I need, thanks! It is possible a worm, therefore, I have to dive. He mentions that for some things the user must have administrator rights; this probably won't be a big problem, but it can limit it a bit.

+3
source share
6 answers

WMI . , WMI .NET , . , , .

SQL- WMI, .

+3

, Windows (WMI), , Windows, . WMI Code Creator Microsoft. .

WMI Windows 2000, Win98 .

, , , WMI, , .

+5

, , , , WMI, .

System.Management #. , , #, , , , . , ( ). LogClass() . , MSDN WMI Classes.

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.IO;

namespace SyTest
{
  class Program
  {
    static StreamWriter specStream;

    static void Main(string[] args)
    {
      FileStream specFile =
          new FileStream("machine-specs.txt",FileMode.Create,FileAccess.Write);
      specStream = new StreamWriter(specFile);

      LogClass("Win32_DesktopMonitor");
      LogClass("Win32_VideoController");
      LogClass("Win32_Processor");
      // etc

      specStream.Close();
      specFile.Close();
    }

    static void LogClass(string strTable)
    {
      if (strTable.Length <= 0) return;
      specStream.Write("--- " + strTable + " ---\r\n\r\n");
      WqlObjectQuery wqlQuery =
          new WqlObjectQuery("SELECT * FROM " + strTable);
      ManagementObjectSearcher searcher =
          new ManagementObjectSearcher(wqlQuery);
      try
      {
        if (searcher.Get().Count <= 0)
        {
          specStream.Write("Class has no instances\r\n\r\n");
        }
        foreach (ManagementObject obj in searcher.Get())
        {
          specStream.Write("* " + obj.ToString() + "\r\n");

          if (obj.Properties.Count <= 0)
          {
            specStream.Write("Class instance has no properties\r\n");
            continue;
          }

          foreach (System.Management.PropertyData prop in obj.Properties)
          {
            LogAttr(obj, prop.Name);
          }

          specStream.Write("\r\n");
        }
      }
      catch { specStream.Write("Class does not exist\r\n\r\n"); }
    }
    static void LogAttr(ManagementObject obj, string str)
    {
      if (str.Length <= 0) return;
      string strValue = "";
      try
      {
        strValue = obj[str].ToString();
        try
        {
          string[] pstrTmp = ((string[])obj[str]);
          if (pstrTmp.Length > 0) strValue = String.Join(", ", pstrTmp);
        }
        catch { } // Problem casting, fall back on original assignment
      }
      catch { strValue = "[UNDEFINED]"; }
      specStream.Write(str + ": " + strValue + "\r\n");
    }
  }
}
+1

, Linux, /proc.

0

If you decide to go with WMI, you can check out Microsoft's WMI Code Creator . This simplifies working with WMI.

0
source

There is a nuget package with a name MissingLinq.Linq2Managementthat completely covered everything related to WMI in a nice strongly typed object. Seems pretty enjoyable.

https://missinglinq.codeplex.com/

0
source

Source: https://habr.com/ru/post/1698275/


All Articles