Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7630017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:59:22+00:00 2026-05-31T05:59:22+00:00

The current structure of my classes goes a little bit like this: PC.Processor.Architecture[0] =

  • 0

The current structure of my classes goes a little bit like this:
PC.Processor.Architecture[0] = The Architecture of the first processor (assuming a multi-processor system).

How I ideally want it is more like this:
PC.Processor[0].Architecture, because it’s a bit more self explanatory this way.

Is there a fairly efficient way of doing this with what I have? Bear in mind there are like, over 9000 properties in each of the classes Processor, Motherboard, Memory etc and WMI calls are not CPU-cheap to run.

Here are the important snippets for my classes

class PC
{
    public Processor Processor;
    public Motherboard Motherboard;

    // Constructor
    public PC()
    {
        Processor = new Processor();
        Motherboard = new Motherboard();
    }

    // Method to get all info sequentially
    public void GetAllInfo()
    {
        Processor.GetInfo();
        Motherboard.GetInfo();
    }
}

class Processor
{
    public string[] Architecture;
    public string[] Availability;
    public UInt16[] Cores;

    public void GetInfo()
    {
        // Get WMI Information from custom process
        // Returns as an array of ManagementObjects for each matched device (which is a bit like an array of dictionaries)
        ManagementObject[] WMIData = DataRetriever.GetWMIData("Win32_Processor");
        try
        {
            for (int i = 1; i < WMIData.Length; i++)
            {
                this.Architecture[i] = (string)WMIData[i]["Architecture"];
                this.Availability[i] = (string)WMIData[i]["Availability"];
                this.Cores[i] = (UInt16)WMIData[i]["NumberOfCores"];
            }
        }
        catch (NullReferenceException e)
        {
            // To be implemented
        }
    }
}

FURTHERMORE
There may be more than one WMI search query per class. For example, HardDrive needs to make use of both Win32_PhysicalMedia and ATAPI_SmartData (or whatever the class actually is.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:59:24+00:00Added an answer on May 31, 2026 at 5:59 am

    Thanks to everyone who’s responded.
    I’ve come up with a reasonably elegant solution that suits my needs.

    PC Class Example:

    public class PC
    {
        public List<Processor> Processor;
    
        // Constructor
        public PC()
        {
            this.Processor = new List<Processor>();
        }
    
        // Method to get all info sequentially
        public void GetAllInfo()
        {
            // These temporary stores fetch WMI data as ManagementObjects
            // Most cases will only need one WMI class.
            ManagementObject[] WMIDataTemp1;
            ManagementObject[] WMIDataTemp2;
    
            WMIDataTemp1 = DataRetriever.GetWMIData("Win32_Processor");
            foreach (ManagementObject Object in WMIDataTemp1)
            {
                this.Processor.Add(new Processor(Object));
            }
        }
    
        public void RefreshAll()
        {
            // Delete the lists and start again
            // Another option would be to foreach through the list elements and initialise each object again.
            this.Processor.Clear();
            GetAllInfo();
        }
    
        public void RefreshVolatileData()
        {
            // Extra function that will do some cool stuff later.
        }
    }
    

    Processor Class Example:

    public class Processor
    {
        // Define properties
        public string Architecture = "N/A";
        public string Availability = "N/A";
        public UInt32 CacheL2 = 0;
        public UInt32 CacheL3 = 0;
    
        // Overloaded constructor method
        // The one with no arguments does nothing to initialise the class
        // The one with the ManagementObject argument will call GetInfo to arrange the held data into the properties above
        public Processor() { }
        public Processor(ManagementObject wmiProcessor)
        {
            this.GetInfo(wmiProcessor);
        }
    
        // The main information handler for the classes.
        // This splits out the data in the ManagementObject into the class's own properties
        public void GetInfo(ManagementObject wmiProcessor)
        {
            // If anything fails, the try loop will just end without making a fuss
            // Because of the default values, N/A will be displayed everywhere if something fails here.
            try
            {
                this.Architecture = (string)wmiProcessor["Architecture"];
                this.Availability = (string)wmiProcessor["Availability"];
                this.CacheL2 = (UInt32)wmiProcessor["L2CacheSize"];
                this.CacheL3 = (UInt32)wmiProcessor["L3CacheSize"];
            }
            catch (Exception e)
            {
    
            }
        }
    }
    

    Usage example:

    public PC Computer = new PC();
    Computer.GetAllInfo();
    textbox1.Text = Computer.Processor[0].Architecture
    

    In the event a device needs to query more than one WMI class, each additional class can be listed as an extra parameter in the device constructor and GetInfo() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

maybe i am wrong but i seriously i don't like the current structure of
I currently use this style to create a js class like structure: var JSClass
My classes structure is like: class MethodHelper : public QObject, public IMethodHelper { public:
I have the current basic structure for each domain object that I need to
What is the current method of implementing the joined-subclass structure with FluentNHibernate? By current,
How do I locate the current file in the project structure? (Similar to Visual
I have a complex Clojure data structure that I would like to serialize -
My current project is split into multiple classes that correctly represent the way we
I want to structure my Flask app something like: ./site.py ./apps/members/__init__.py ./apps/members/models.py apps.members is
I have a (custom) php framework that contains following structure: app |-classes |-settings core

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.