?
Solved

Capturing system specs in a VB.Net program?

Posted on 2003-03-13
2
Medium Priority
?
410 Views
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
RAM
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?
0
Comment
Question by:BlaikM
2 Comments
 
LVL 28

Accepted Solution

by:
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
        Next
    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
          Next
End Sub
' **************************************
'     **************************************
' Main
' **************************************
'     **************************************
Dim strComputer


Do
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
        Next
    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
        Next

        MessageBox.Show(msg)
    End Sub
End Class
=======================================

for WMI examples set refernece to System.Management.dll
0
 

Author Comment

by:BlaikM
ID: 8136073
Wow!  Thanks for the very thorough answer!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

621 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