Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

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

TableFlipGod

Bronze Coder
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()

[CODE lang="csharp" title="ReturnCPUInfo"]ManagementObjectSearcher mos =
new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Processor");
foreach (ManagementObject mo in mos.Get())
{
label1.Text = ("CPU: " + mo["Name"].ToString());
}[/CODE]

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).

[CODE lang="csharp" title="ReturnGPUInfo"]ManagementObjectSearcher mos2 =
new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController");
foreach (ManagementObject mo in mos2.Get())
{
GPUName.Text = ("GPU: " + mo["Name"].ToString());
}[/CODE]

Again this does the exact same thing and it just returns GPU info.


[CODE lang="csharp" title="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");
}[/CODE]

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:
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 :)
 
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!
 
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 :).
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom