Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
' mak System.Diagnostics
' make sure that using System.Security.Principal; is included
Imports System.Security.Principal
' make sure that using System.Diagnostics; is included
Imports System.Management
' add reference system.management (.NET directory)
Public Class Form1
Public Enum ChassisTypes
Other = 1
Unknown
Desktop
LowProfileDesktop
PizzaBox
MiniTower
Tower
Portable
Laptop
Notebook
Handheld
DockingStation
AllInOne
SubNotebook
SpaceSaving
LunchBox
MainSystemChassis
ExpansionChassis
SubChassis
BusExpansionChassis
PeripheralChassis
StorageChassis
RackMountChassis
SealedCasePC
End Enum
Public Shared Function GetCurrentChassisType() As ChassisTypes
Dim systemEnclosures As New ManagementClass("Win32_SystemEnclosure")
For Each obj As ManagementObject In systemEnclosures.GetInstances()
For Each i As Integer In DirectCast(obj("ChassisTypes"), UInt16())
If i > 0 AndAlso i < 25 Then
Return CType(i, ChassisTypes)
End If
Next
Next
Return ChassisTypes.Unknown
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MessageBox.Show(GetCurrentChassisType().ToString())
End Sub
End Class
No comments:
Post a Comment