System Information - Extensive

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
5 posts Page 1 of 1
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

System Information - Extensive
CodenStuff
Hello,

Alot of people have been asking how to get system information into applications and you can do this in a couple of ways but I think this way is the best and you can get any information you want.

This code uses WMI to get specific information about processors, memory, OS, motherboard, drivers, hardware and everything else to do with the users system.

To make things easier Microsoft have a little application called WMI Code Creator that you can download for free here: http://www.microsoft.com/downloads/deta ... laylang=en
sshot-9.png
When you run the application it will look like the screenshot above (without the colored borders). Ill explain a little bit about the interface and the sections ive highlighted in the screenshot.

The area marked in RED is where you select which part of the system you want information from such as Processor, BIOS and so on. Once youve made your selection you will get a list of all available commands in the box highlighted in GREEN. If you click one of these commands you will see a code sample in the box highlighted in BLUE which you can use in your application to show the selected piece of information. If you click "Code Language" in the menu bar you can select which programming language you need code for, VB.NET..C# or VBScript.

But we wont be using the code from that blue box in this tutorial because theres too much of it and will take up alot of room in your code if you wanted alot of information. We are going to do it in a much quicker and simpler way so start by creating a new project.

Before we do anything we need to go into Project > Project Properties and click "References". Then add a reference to "System.Management.dll"

Now in code view we will add a function to our code that will do most of the hard work for us and save us loads of time. So add this function code:
Code: Select all
Private Shared Function AskForTheInfo(ByVal ClassName As String, ByVal PropInfo As String) As String
        Dim WinFoSearch As New ManagementObjectSearcher("Select * from Win32_" & ClassName)
        For Each WinObj As ManagementObject In WinFoSearch.Get()
            Try
                Return WinObj(PropInfo).ToString()
            Catch e As Exception
                MessageBox.Show(e.Message + "   " + ClassName + " - " + PropInfo) 'JUST INCASE YOU MADE A MISTAKE IT WILL TELL YOU WHERE IT IS!
            End Try
        Next WinObj
        Return ""
    End Function
OK we are ready to get our information and display it somewhere like in a Textbox or Label. Before we can get our information we need to know what we are getting information from and the information we want from it.

On the screenshot in the RED box I have selected "Win32_Processor" but we want to cut out "Win32_" and just use the name of what we want information from..in this case its "Processor".
Now you need to choose a command from the box highlighted in GREEN and for this example I will use "MaxClockSpeed".

So we now know what we want information from and what information we want. The code you would use to show this information is:
Code: Select all
AskForTheInfo("Processor", "MaxClockSpeed")
If you wanted to display that in a Textbox then you simply use:
Code: Select all
TextBox1.Text = AskForTheInfo("Processor", "MaxClockSpeed")
And you use the same short piece of code for everything else. If you wanted to show the BIOS name you would use:
Code: Select all
AskForTheInfo("BIOS", "Name")
Or to show the BIOS Manufacturer:
Code: Select all
AskForTheInfo("BIOS", "Manufacturer")

Thats all you have to do ;) nice and easy!

I hope someone finds it useful cooll;
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: System Information - Extensive
Usman55
At least I found it useful!

Thanks!
Image
User avatar
AleRi8
Top Poster
Top Poster
Posts: 153
Joined: Sun Sep 20, 2009 2:30 pm

Re: System Information - Extensive
AleRi8
Wow Thanks for show me how to use this
check out my software
win7 itweaker basic £4.50
viewtopic.php?f=70&t=793
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Thanks Codenstuff, this makes it a lot easier to understand :)

Chris
Image
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

Re: System Information - Extensive
Lewis
Its easier for me aswell Thanks! :D
Image
5 posts Page 1 of 1
Return to “Tutorials”