[c#] How to show system info like i did with my program.

TableFlipGod

Coder
May 13, 2019
82
18
9
Before I get into this I just wanted to point out if you need any help just make a thread with help and I will be more than happy to help you :)
114


So first off you're going to create a new project. Specially a Windows Forms in c#.

Next Design it how you want. But you have to have a few labels to show the text.

Now the fun bit!!! Copy this code and paste it into your program's start function.
Code:
public Form1()
ReturnCPUInfo:
ManagementObjectSearcher mos =
              new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
            foreach (ManagementObject mo in mos.Get())
            {
                label1.Text = ("CPU: " + mo["Name"].ToString());
            }
So now ill explain what this code does. It creates a new management Object Searcher from the root system and selects every Win32_Processor or just the processor name like in controlpanel or in task manager.

Then ill do the same for the GPU. Create a new label and place it where you want it to show (preferably and for best Results the very left under the cpu label).

ReturnGPUInfo:
ManagementObjectSearcher mos2 =
              new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController");
            foreach (ManagementObject mo in mos2.Get())
            {
                GPUName.Text = ("GPU: " + mo["Name"].ToString());
            }
Again this does the exact same thing and it just returns GPU info.


ReturnRAMInfo:
ManagementObjectSearcher query1 = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem");
            query1 = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
            ManagementObjectCollection queryCollection1 = query1.Get();

queryCollection1 = query1.Get();
            foreach (ManagementObject mo in queryCollection1)
            {
                UInt64 mem = Convert.ToUInt64(mo["totalphysicalmemory"]);
                RAMName.Text = ("RAM: " + mem / 1000000000 + "GB");
            }
So this one is a bit tricky! What ive done here is it gets the ram as a UInt64 so it can store a pretty big number, but if we were to compile the code without the mem / 1000000000 then what would it do?


Well if you convert bytes to gigabytes it would be 1000000000 times the amount of bytes

Ex. 1 byte -> 1 gb = 1000000000 bytes

So you divide it to show the amount of RAM in 1-2 numbers depends if you're on a server then 3.

Next tutorial I will be talking about how to get storage drives info (amounts and types)
 
Last edited:
  • Like
Reactions: Malcolm

Ghost

Active Coder
Moderator
Apr 19, 2019
303
140
43
I am no expert with C, but I am glad you shared this!
I haven't tested it or anything, but assuming it does in fact work... Thank you so much for contributing :)
I am sure this will help some current & future members, as well as some visitors from Google or Bing. Even besides the system info, you created a pretty cool GUI too, so that's nice. I would love to see the code for constructing the GUI window :)
 
  • Like
Reactions: TableFlipGod

TableFlipGod

Coder
May 13, 2019
82
18
9
I am no expert with C, but I am glad you shared this!
I haven't tested it or anything, but assuming it does in fact work... Thank you so much for contributing :)
I am sure this will help some current & future members, as well as some visitors from Google or Bing. Even besides the system info, you created a pretty cool GUI too, so that's nice. I would love to see the code for constructing the GUI window :)
Thank You!
 
  • Like
Reactions: Ghost

Mandiux

New Coder
Aug 6, 2019
14
7
4
Great tutorial! User interface is modern and clean! Did you use MetroModernUI for the interface?
 

TableFlipGod

Coder
May 13, 2019
82
18
9
I am no expert with C, but I am glad you shared this!
I haven't tested it or anything, but assuming it does in fact work... Thank you so much for contributing :)
I am sure this will help some current & future members, as well as some visitors from Google or Bing. Even besides the system info, you created a pretty cool GUI too, so that's nice. I would love to see the code for constructing the GUI window :)
Actually this is c#. And there isnt any code for contructing this Ui. Only making it function :).