Capturing system specs in a VB.Net program?

Posted on 2003-03-13
Medium Priority
Last Modified: 2012-06-27
My VB.Net application needs to record certain specs about the machine it's running on to include in its log file.  Specifically, I'm interested in:

Processor type & clock speed
Disk type (IDE or SCSI)
Overall size and free space on the working drive (the application knows the letter)
RAID level

How do I get access to information like this from within my application?
Question by:BlaikM
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 28

Accepted Solution

iboutchkine earned 500 total points
ID: 8132499
Processor info

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MsgBox("Number of CPUs: " & Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"))
        MsgBox("CPU Architecture: " & Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"))
        MsgBox("CPU Identifier: " & Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER"))
        MsgBox("CPU Level: " & Environment.GetEnvironmentVariable("PROCESSOR_LEVEL"))
        MsgBox("CPU Revision: " & Environment.GetEnvironmentVariable("PROCESSOR_REVISION"))
    End Sub
End Class

   or you can get info using WMI

Imports System.Management

   Private Sub btnProcessor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcessor.Click
        ' This is to show how to use the SelectQuery object in the place of a SELECT
        ' statement.
        Dim query As New SelectQuery("Win32_processor")

        'ManagementObjectSearcher retrieves a collection of WMI objects based on
        ' the query.
        Dim search As New ManagementObjectSearcher(query)

        ' Display each entry for Win32_processor
        Dim info As ManagementObject
        For Each info In search.Get()
            txtOutput.Text = "Processor: " & info("caption").ToString() & CRLF
    End Sub

here is VBScript to get memory info

Sub ListMemoryProperties( strComputer )
    Dim objWMIService, colItems
          Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
          Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
          For Each objItem In colItems
          Wscript.Echo "BankLabel: " & objItem.BankLabel
          Wscript.Echo "Capacity: " & objItem.Capacity
          Wscript.Echo "Caption: " & objItem.Caption
          Wscript.Echo "CreationClassName: " & objItem.CreationClassName
          Wscript.Echo "DataWidth: " & objItem.DataWidth
          Wscript.Echo "Description: " & objItem.Description
          Wscript.Echo "DeviceLocator: " & objItem.DeviceLocator
          Wscript.Echo "FormFactor: " & objItem.FormFactor
          Wscript.Echo "HotSwappable: " & objItem.HotSwappable
          Wscript.Echo "InstallDate: " & objItem.InstallDate
          Wscript.Echo "InterleaveDataDepth: " & objItem.InterleaveDataDepth
          Wscript.Echo "InterleavePosition: " & objItem.InterleavePosition
          Wscript.Echo "Manufacturer: " & objItem.Manufacturer
          Wscript.Echo "MemoryType: " & objItem.MemoryType
          Wscript.Echo "Model: " & objItem.Model
          Wscript.Echo "Name: " & objItem.Name
          Wscript.Echo "OtherIdentifyingInfo: " & objItem.OtherIdentifyingInfo
          Wscript.Echo "PartNumber: " & objItem.PartNumber
          Wscript.Echo "PositionInRow: " & objItem.PositionInRow
          Wscript.Echo "PoweredOn: " & objItem.PoweredOn
          Wscript.Echo "Removable: " & objItem.Removable
          Wscript.Echo "Replaceable: " & objItem.Replaceable
          Wscript.Echo "SerialNumber: " & objItem.SerialNumber
          Wscript.Echo "SKU: " & objItem.SKU
          Wscript.Echo "Speed: " & objItem.Speed
          Wscript.Echo "Status: " & objItem.Status
          Wscript.Echo "Tag: " & objItem.Tag
          Wscript.Echo "TotalWidth: " & objItem.TotalWidth
          Wscript.Echo "TypeDetail: " & objItem.TypeDetail
          Wscript.Echo "Version: " & objItem.Version
End Sub
' **************************************
'     **************************************
' Main
' **************************************
'     **************************************
Dim strComputer

strComputer = inputbox( "Please enter a computername or . For local computer", "Input" )
Loop until strComputer <> ""
ListMemoryProperties( strComputer )

Disk size

Imports System.Management

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim wmi As ManagementClass
        Dim objs As ManagementObjectCollection
        Dim obj As ManagementObject

        wmi = New ManagementClass("Win32_LogicalDisk")
        objs = wmi.GetInstances()
        For Each obj In objs
            If Convert.ToInt32(obj("drivetype")) <> 4 Then
                MsgBox("Size=" & Convert.ToDouble(obj("Size")) / (1024.0# * 1024.0#))
            End If
    End Sub
End Class

Free disk space

'ref NET   System.Management

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Const HARD_DISK = 3
        Dim strComputer As String = "."
        Dim objWMIService As Object = GetObject("winmgmts:" _
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Dim colDisks As Object = objWMIService.ExecQuery _
            ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
        Dim objDisk As Object
        Dim msg As String

        For Each objDisk In colDisks
            msg &= "DeviceID: " & vbTab & objDisk.DeviceID & _
            " Free Disk Space: " & vbTab & objDisk.FreeSpace & vbCrLf

    End Sub
End Class

for WMI examples set refernece to System.Management.dll

Author Comment

ID: 8136073
Wow!  Thanks for the very thorough answer!

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question