How can I view the System Information using VB6?

Hiii guys,

How can I view the System Information using VB6?
for example I want to view the following:
- OS Type
- CPU Type and Speed
- RAM Speed + (number of slots used and free)---> this is not important but if it's possible it would be better
- HDD used and free space
- Motherboard type
- UserName logged in
- Sofwtare and Patches installed

I found some applications but most of them are not that accurate and don't have the information I need.

Thanks for your help and I'll be waiting for your reply.
The-CoolestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ralf KlattEmployee in Civil ServiceCommented:
Hi,

You'll find a lot of information and samples at: http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx


As a sample application for CPU Information you may use this code:

VERSION 5.00
Begin VB.Form Form1
   Caption         =   "WMI Demo - CPU Information"
   ClientHeight    =   3930
   ClientLeft      =   2415
   ClientTop       =   1845
   ClientWidth     =   8775
   LinkTopic       =   "Form1"
   ScaleHeight     =   3930
   ScaleWidth      =   8775
   Begin VB.TextBox txtCpu
      Height          =   2715
      Left            =   3645
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      TabIndex        =   2
      Top             =   870
      Width           =   3705
   End
   Begin VB.ListBox lstCPU
      Height          =   2595
      Left            =   660
      TabIndex        =   0
      Top             =   870
      Width           =   2580
   End
   Begin VB.Label lblInfo
      AutoSize        =   -1  'True
      Caption         =   "Information for Selected CPU"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   3690
      TabIndex        =   4
      Top             =   555
      Width           =   2490
   End
   Begin VB.Label lblTitle
      AutoSize        =   -1  'True
      Caption         =   "Label1"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   2070
      TabIndex        =   3
      Top             =   210
      Width           =   585
   End
   Begin VB.Label lblCPUList
      AutoSize        =   -1  'True
      Caption         =   "CPUs"
      BeginProperty Font
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   735
      TabIndex        =   1
      Top             =   555
      Width           =   480
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'***********************************************************\
'NOTES:

'YOU MUST HAVE WMI SDK INSTALLED.  YOU CAN GET IT AT
'http://msdn.microsoft.com/downloads/sdks/wmi/default.asp
'***********************************************************************

Private asCpuPaths() As String
Private m_objCPUSet As SWbemObjectSet
Private m_objWMINameSpace As SWbemServices
Option Explicit

Private Sub cmdDone_Click()
Unload Me
End Sub

Private Sub Form_Load()


Dim oCpu As SWbemObject 'WMI Object, in this case, local CPUs
Dim sPath As String, sCaption As String

Dim lElement As Long
ReDim asCpuPaths(0) As String


On Error GoTo ErrorHandler

'Get Default NameSpace, which will be the one for the local machine
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Set m_objWMINameSpace = GetObject("winmgmts:")
lstCPU.Clear


'Get CPU set

Set m_objCPUSet = m_objWMINameSpace.InstancesOf("Win32_Processor")
sCaption = m_objCPUSet.Count & " processor"
If m_objCPUSet.Count <> 1 Then sCaption = sCaption & "s"
sCaption = sCaption & " detected on this machine"
lblTitle.Caption = sCaption
'Populate list box with CPU names
               
For Each oCpu In m_objCPUSet
     With oCpu
        sPath = .Path_ & ""
            If sPath <> "" Then
                lstCPU.AddItem .Name
                'save path to array, so on machines with multiple CPUs,
                'each can be identified and their info loaded into text box
               
                lElement = IIf(asCpuPaths(0) = "", 0, UBound(asCpuPaths) + 1)
                ReDim Preserve asCpuPaths(lElement) As String
                asCpuPaths(lElement) = sPath
            End If
     End With
Next
If lstCPU.ListCount <> 0 Then lstCPU.ListIndex = 0
     
 



CleanUp:
Set oCpu = Nothing

Exit Sub

ErrorHandler:
MsgBox "CPU Information could not be displayed due to the following error: " & Err.Description, , "WMI Demo Failed"
GoTo CleanUp
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set m_objCPUSet = Nothing
Set m_objWMINameSpace = Nothing
End Sub

Private Sub lstCPU_Click()
Dim oCpu As SWbemObject
'Refer to SDK documentation for more detail about each of these properties
Dim sInfoString As String
On Error Resume Next
Set oCpu = m_objCPUSet(asCpuPaths(lstCPU.ListIndex))
With oCpu
    sInfoString = "Description: " & .Description & vbCrLf
    sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
    sInfoString = sInfoString & "Status: " & .Status & vbCrLf
    sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
    sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
    sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
    sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
    sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
    sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported
End With
txtCpu.Text = sInfoString

End Sub
'Conversions from code to string were developed
'based on information in WMI SDK documentation
Private Function AvailabilityToString(Code As Integer) As String
Dim sAns As String

Select Case Code
    Case 1, 2
        sAns = "Unknown"
    Case 3
        sAns = "Running/Full Power"
    Case 4
        sAns = "Warning"
    Case 5
        sAns = "In Test"
    Case 6
        sAns = "Not Applicable"
    Case 7
        sAns = "Power Off"
    Case 8
        sAns = "Off Line"
    Case 9
        sAns = "Off Duty"
    Case 10
        sAns = "Degraded"
    Case 11
        sAns = "Not Installed"
    Case 12
        sAns = "Install Error"
    Case 13
        sAns = "Power Save - Unknown"
    Case 14
        sAns = "Power Save - Low Power Mode"
    Case 15
        sAns = "Power Save - Standby"
    Case 16
        sAns = "Power Cycle"
    Case 17
        sAns = "Power Save - Warning"
    Case Else
        sAns = "Unknown"
End Select
AvailabilityToString = sAns

End Function


       
Best regards,
Raisor

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StillUnAwareCommented:
Shane Russell2nd Line Desktop SupportCommented:
If you are just after an app that displays that belarc is very good :

http://www.belarc.com/free_download.html

If you want to do this yourself then it will most likely be a case of using wmi.

Scriptomatic 2.0 will help you out a lot with regards to letting you get the wmi code you need to attain each coded example of how to attain the info you are after.

Go here to get scriptomatic 2.0 :

http://www.microsoft.com/downloads/details.aspx?FamilyID=09dfc342-648b-4119-b7eb-783b0f7d1178&DisplayLang=en

Another good site with regards to visual basic 6 and it has plenty of examples on how to do numerous things is this site :

vbnet.mvps.org

Just use the search link on the left side and search for what you are looking for and it should come up with examples.

Also take a look here :

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__computer_hardware.asp
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

The-CoolestAuthor Commented:
Thanks StillUnAware. The link you provided is helpful. But unfortunately the most important information it doesn't show, for example: The speed and type of CPU, The free and used space of the HDD, The speed of  RAM...etc.
Shane Russell2nd Line Desktop SupportCommented:
Here is an extremely good example , go here :

http://vbturk.net/idsorgula.asp?id=781

Copy and paste that visual basic code into a new project and make sure you put a combobox and a listview into the project, to add a listview right click on the toolbar and click add component, scroll down until you get to "microsoft windows common controls" add the sp6 or one of the latest versions of them controls in by checking the box and clicking on ok, also go to project --> references and make sure that wmi scripting V1.2 is checked and also that microsoft scripting runtime is checked.
Shane Russell2nd Line Desktop SupportCommented:
wth that example you are basically using the combo box to select the wmi classes and then it enumerates the info into the list view :)
Shane Russell2nd Line Desktop SupportCommented:
If you cant figure it out let me know and I can upload the one I made using that example from that site.
Shane Russell2nd Line Desktop SupportCommented:
Go here for the example :

http://www.geocities.com/gecko_au2003/system.htm

I had to zip it up but its in there :)

Obviously you will need to take out figure out which classes you want to use by going through them and seeing which info it returns and deciding which ones are relevant to you, once you establish that you can either post back and let me know which classes return the info you want and I can help you put together a completed vb 6 app to do it.

If you would like ?
Shane Russell2nd Line Desktop SupportCommented:
Just as an FYI - that vb app I knocked together from that site I gave you is missing a few classes such as this one :

Win32_OperatingSystem

You can view examples on how to do things with that class and other ones by going here, I already referenced this site above :)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_tasks__computer_hardware.asp
Shane Russell2nd Line Desktop SupportCommented:
If you notice any classes missing from that vb app literally just add a line like so to the form load event :

Combo1.AddItem "Win32_OperatingSystem"

So for the Win32_OperatingSystem class I just added the above line in the form load event, just do the same for any other classes that you notice are missing.
Ralf KlattEmployee in Civil ServiceCommented:
Hi,

@The-Coolest: ... by the way, what's wrong, with the provided "WMI Demo - CPU Information" source code? It's infact giving you:

    sInfoString = "Description: " & .Description & vbCrLf
    sInfoString = sInfoString & "Processor ID: " & .ProcessorID & vbCrLf
    sInfoString = sInfoString & "Status: " & .Status & vbCrLf
    sInfoString = sInfoString & "Manufacturer: " & .Manufacturer & vbCrLf
    sInfoString = sInfoString & "Availability: " & AvailabilityToString(.Availability) & vbCrLf
    sInfoString = sInfoString & "Load Percentage: " & .LoadPercentage & vbCrLf
    sInfoString = sInfoString & "Current Clock Speed: " & .CurrentClockSpeed & " MHz" & vbCrLf
    sInfoString = sInfoString & "Maximum Clock Speed: " & .MaxClockSpeed & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Size: " & .L2CacheSize & vbCrLf
    sInfoString = sInfoString & "Level 2 Cache Speed: " & .L2CacheSpeed & vbCrLf
    sInfoString = sInfoString & "Power Management Supported: " & .PowerManagementSupported



Best regards,
Raisor
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.