5 Replies - 1284 Views - Last Post: 24 January 2012 - 08:43 PM Rate Topic: -----

#1 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Getting info about hardware in the computer?

Posted 07 January 2012 - 09:14 AM

Hello people!

I was looking around the web for some C# classes that would let me get information about the hardware of the computer that the application is run by. But i couldn't find any classes that does it.

And im also intrested to ask if there is a way of coding to get something like the name of the graphics card inside the computer through code?
Is This A Good Question/Topic? 0
  • +

Replies To: Getting info about hardware in the computer?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5442
  • View blog
  • Posts: 11,676
  • Joined: 02-June 10

Re: Getting info about hardware in the computer?

Posted 07 January 2012 - 09:24 AM

Do you mean like the Environment class?


Finding answers to specific problems:
Sometimes just knowing where to look can make all the difference. Google is your friend.
Search with either "C#" or "MSDN" as the first word: "MSDN Picturebox", "C# Custom Events", "MSDN timer" etc.
How to do a good search that will get you targeted answers.

I found plenty of examples on how to get the video card name by Googling with the terms:
"C# video card name"

Sometimes its just a matter of learning how to Google better.

Out of curiosity, why are looking for specific hardware details? As a rule we try to write software that DOESN'T rely on knowing these things in order to make it more universally executable. Very rarely should one need to know the exact video card installed. More likely you just need to know if it is DirectX capable for example. You don't need to know which make of serial port chipset is installed, just a list of the available COM ports.

This post has been edited by tlhIn`toq: 07 January 2012 - 09:24 AM

Was This Post Helpful? 0
  • +
  • -

#3 TheCompBoy  Icon User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 314
  • Joined: 21-April 11

Re: Getting info about hardware in the computer?

Posted 07 January 2012 - 09:25 AM

I thought i could for fun make an application that shows all information about your computer.

Big thanks for the help!

This post has been edited by TheCompBoy: 07 January 2012 - 09:25 AM

Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

Re: Getting info about hardware in the computer?

Posted 08 January 2012 - 10:37 AM

You probably want to look into WMI in that case.
Was This Post Helpful? 2
  • +
  • -

#5 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Getting info about hardware in the computer?

Posted 08 January 2012 - 04:58 PM

I've been using the WMI class as well and it is a super in depth resource about all your computer information needs. This may help you read through the information you want. I use the following code to look through a WMI class and then copy it to Excel to analyze the contents.

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Management;
using System.Text;
using System.Windows.Forms;


namespace MySystemScanner
{
    
    class Program
    {
        static StringBuilder myOutput = new StringBuilder();
        [STAThread]
        static void Main(string[] args)
        {
            string myQuery = "Win32_NetworkAdapter"; //change to any WMI class
            string myCondition = "Index=7"; //use for conditional statements
            string[] myProperties = {"IPAddress"}; //use for specific properties

            StringCollection stringCollection = new StringCollection();
            stringCollection.AddRange(myProperties);

            SelectQuery selectQuery = new SelectQuery(myQuery);
            //selectQuery.SelectedProperties = stringCollection; 
            //selectQuery.Condition = myCondition;
            ManagementObjectSearcher moSearcher = new ManagementObjectSearcher(selectQuery);
            printManagement(moSearcher, myQuery);
            Clipboard.SetText(myOutput.ToString());
            Console.In.ReadLine();
        }
        private static void printManagement(ManagementObjectSearcher searcher, string objectString)
        {
            Console.Out.WriteLine("Accessing:" + objectString);
            foreach (ManagementObject myObject in searcher.Get())
            {
                foreach (PropertyData prop in myObject.Properties)
                {
                    if (prop.Value != null)
                    {
                        Console.WriteLine("{0} : {1}", prop.Name, prop.Value);
                        myOutput.AppendLine(prop.Type + "\t" + prop.Name + "\t" + prop.Value);
                        if (prop.IsArray)
                        {
                            Array values = prop.Value as Array;
                            for (int i=0; i<values.Length; i++)
                            {
                                object value = values.GetValue(i);
                                Console.WriteLine("\t>{0}", value.ToString());
                                myOutput.AppendLine(value.GetType() + "\t" + prop.Name + "[" + i + "]\t" + value.ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} : *NULL*", prop.Name);
                        myOutput.AppendLine(prop.Type + "\t" + prop.Name + "\t*NULL*");
                    }
                }
            }
        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#6 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Getting info about hardware in the computer?

Posted 24 January 2012 - 08:43 PM

just updated my code

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Data;
using System.Management;
using System.Text;
using System.Windows.Forms;


namespace MySystemScanner
{

    class Program
    {
        static StringBuilder myOutput = new StringBuilder();
        [STAThread]
        static void Main(string[] args)
        {
            string wmiClass = "Win32_NetworkAdapter"; //change to any WMI class
            string[] properties = { "MACAddress" }; //use for specific properties

            //three examples showing how to use my code
            myOutput = printManagement(wmiClass, null, properties);
            Clipboard.SetText(myOutput.ToString());
            Console.Write("Hit enter to continue, program paused so you can paste contents of clipboard into Excel");
            Console.In.ReadLine();

            myOutput = printManagement("Win32_DiskDrive", "Index=0", null);
            Clipboard.SetText(myOutput.ToString());
            Console.Write("Hit enter to continue, program paused so you can paste contents of clipboard into Excel");
            Console.In.ReadLine();

            myOutput = printManagement("Win32_DiskDrive", null, null);
            Clipboard.SetText(myOutput.ToString());
            Console.Write("Last call is in Clipboard, hit enter to quit");
            Console.In.ReadLine();

        }
        /*
         * @Return StringBuilder for use with cliboard, or whatever you want
         * @Param string WMIClass - a string that represents a WMI class not case sensitive
         *      and the WMI class is defaulted to "root\\wmi"
         *http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084%28v=vs.85%29.aspx
         *
         * @Param string condition - a string that represents the conditions for the WQL. Can be null
         * @Param string[] properties - a string array that is the desired properties from this WMI Class. Can be null
         */
        private static StringBuilder printManagement(string WMIClass, string condition, string[] properties)
        {
            SelectQuery selectQuery = new SelectQuery(WMIClass, condition, properties);
            StringBuilder sb = new StringBuilder();
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);

            Console.Out.WriteLine("Accessing:" + selectQuery.QueryString);
            foreach (ManagementObject myObject in searcher.Get())
            {
                foreach (PropertyData prop in myObject.Properties)
                {
                    if (prop.Value != null)
                    {
                        Console.WriteLine("{0} : {1}", prop.Name, prop.Value);
                        sb.AppendLine(prop.Type + "\t" + prop.Name + "\t" + prop.Value);
                        if (prop.IsArray)
                        {
                            Array values = prop.Value as Array;
                            for (int i = 0; i < values.Length; i++)
                            {
                                object value = values.GetValue(i);
                                Console.WriteLine("\t>{0}", value.ToString());
                                sb.AppendLine(value.GetType() + "\t" + prop.Name + "[" + i + "]\t" + value.ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("{0} : *NULL*", prop.Name);
                        sb.AppendLine(prop.Type + "\t" + prop.Name + "\t*NULL*");
                    }
                }
            }
            return sb;
        }
    }
}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1