本文汇集了中得到计算机硬件信息的一些功能
得到显示器分辨率
Dim X As Short = System<a _blank>Windows</a>FormsScreenPrimaryScreenBoundsWidth
Dim Y As Short = SystemWindowsFormsScreenPrimaryScreenBoundsHeight
MsgBox(您的显示器分辨率是 & X & X & Y)
得到特殊文件夹的路径
Desktop桌面文件夹路径
MsgBox(EnvironmentGetFold<a _blank>ERP</a>ath(EnvironmentSpecialFolderDesktopDirectory))
Favorites收藏夹路径
MsgBox(EnvironmentGetFolderPath(EnvironmentSpecialFolderFavorites))
Application Data路径
MsgBox(EnvironmentGetFolderPath(EnvironmentSpecialFolderApplicationData))
通用写法
Dim SPEC As String = EnvironmentGetFolderPath(EnvironmentSpecialFolderXXXXXXX)
XXXXXXX是特殊文件夹的名字
得到操作系统版本信息
MsgBox(EnvironmentOSVersionToString)
得到当前登录的用户名
MsgBox(EnvironmentUserName)
得到当前应用程序的路径
MsgBox(EnvironmentCurrentDirectory)
打开和关闭CDROM
先新建模块
Module mciAPIModule
Declare Function mciSendString Lib winmmdll Alias mciSendStringA _
(ByVal lpstrCommand As String ByVal lpstrReturnString As String _
ByVal uReturnLength As Integer ByVal hwndCallback As Integer) As Integer
End Module
打开CDROM
Dim lRet As Long
lRet = mciSendString(set cdAudio door open & )
关闭CDROM
Dim lRet As Long
lRet = mciSendString(set cdAudio door Closed & )
更多请参见
?url=/library/enus/multimed/mmcmdstr_eycasp
得到计算机IP和计算机全名
Dim MYIP As SystemNetIPHostEntry = SystemNetDnsGetHostByName(SystemNetDnsGetHostName)
MsgBox(您的IP地址 & (MYIPAddressListGetValue()ToString))
MsgBox(您的计算机全名 & (MYIPHostNameToString))
使用win_operatingSystem (wmi Class)得到计算机信息
添加ListBox在Form_Load事件里并引用systemManagment
Dim opSearch As New ManagementObjectSearcher(SELECT * FROM Win_OperatingSystem)
Dim opInfo As ManagementObject
For Each opInfo In opSearchGet()
ListBoxItemsAdd(Name: & opInfo(name)ToString())
ListBoxItemsAdd(Version: & opInfo(version)ToString())
ListBoxItemsAdd(Manufacturer: & opInfo(manufacturer)ToString())
ListBoxItemsAdd(Computer name: & opInfo(csname)ToString())
ListBoxItemsAdd(Windows Directory: & opInfo(windowsdirectory)ToString())
Next
列出计算机安装的全部字体并添加到ListBox
新建Form并添加ListBox和Button
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
Dim fntCollection As InstalledFontCollection = New InstalledFontCollection()
Dim fntFamily() As FontFamily
fntFamily = fntCollectionFamilies
ListBoxItemsClear()
Dim i As Integer =
For i = To fntFamilyLength
ListBoxItemsAdd(fntFamily(i)Name)
Next
End Sub
使用Win_Processor列出处理器的信息
Imports SystemManagement
Public Class Form
Inherits SystemWindowsFormsForm
#Region Windows 窗体设计器生成的代码
Public Sub New()
MyBaseNew()
该调用是 Windows 窗体设计器所必需的
InitializeComponent()
在 InitializeComponent() 调用之后添加任何初始化
End Sub
窗体重写 dispose 以清理组件列表
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
componentsDispose()
End If
End If
MyBaseDispose(disposing)
End Sub
Windows 窗体设计器所必需的
Private components As SystemComponentModelIContainer
注意: 以下过程是 Windows 窗体设计器所必需的
可以使用 Windows 窗体设计器修改此过程
不要使用代码编辑器修改它
Friend WithEvents ListBox As SystemWindowsFormsListBox
Friend WithEvents Button As SystemWindowsFormsButton
<SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent()
MeListBox = New SystemWindowsFormsListBox
MeButton = New SystemWindowsFormsButton
MeSuspendLayout()
ListBox
MeListBoxLocation = New SystemDrawingPoint( )
MeListBoxName = ListBox
MeListBoxSize = New SystemDrawingSize( )
MeListBoxTabIndex =
Button
MeButtonLocation = New SystemDrawingPoint( )
MeButtonName = Button
MeButtonSize = New SystemDrawingSize( )
MeButtonTabIndex =
MeButtonText = 装载计算机处理器信息
Form
MeAutoScaleBaseSize = New SystemDrawingSize( )
MeClientSize = New SystemDrawingSize( )
MeControlsAddRange(New SystemWindowsFormsControl() {MeButton MeListBox})
MeText = 计算机处理器信息
MeResumeLayout(False)
End Sub
#End Region
Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) _
Handles ButtonClick
Dim ProcQuery As New SelectQuery(Win_Processor)
Dim ProcSearch As New ManagementObjectSearcher(ProcQuery)
Dim ProcInfo As ManagementObject
For Each ProcInfo In ProcSearchGet()
Call processorfamily(ProcInfo(Family)ToString)
ListBoxItemsAdd(Description: & ProcInfo(Description)ToString())
ListBoxItemsAdd(caption: & ProcInfo(caption)ToString())
ListBoxItemsAdd(Architecture: & ProcInfo(Architecture)ToString())
Call processortype(ProcInfo(ProcessorType)ToString())
Call CpuStat(ProcInfo(CpuStatus)ToString)
ListBoxItemsAdd(MaxClockSpeed: & ProcInfo(MaxClockSpeed)ToString() & MHZ)
ListBoxItemsAdd(LCacheSpeed: & ProcInfo(LCacheSpeed)ToString() & MHZ)
ListBoxItemsAdd(ExtClock: & ProcInfo(LCacheSpeed)ToString() & MHZ)
ListBoxItemsAdd(ProcessorId: & ProcInfo(ProcessorId)ToString())
ListBoxItemsAdd(AddressWidth: & ProcInfo(AddressWidth)ToString() & Bits)
ListBoxItemsAdd(DataWidth: & ProcInfo(DataWidth)ToString() & Bits)
ListBoxItemsAdd(Version: & ProcInfo(Version)ToString())
ListBoxItemsAdd(ExtClock: & ProcInfo(ExtClock)ToString() & MHZ)
Next
End Sub
Function processorfamily(ByVal procssfam)
Dim processtype
Select Case procssfam
Case
processtype = Other
Case
processtype = Unknown
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype = Pentium brand
Case
processtype = Pentium Pro
Case
processtype = Pentium II
Case
processtype = Pentium processor with MMX technology
Case
processtype = Celeron
Case
processtype = Pentium II Xeon
Case
processtype = Pentium III
Case
processtype = M Family
Case
processtype = M Family
Case
processtype = K Family
Case
processtype = K Family
Case
processtype = K
Case
processtype = K
Case
processtype = AMD Athlon Processor Family
Case
processtype = AMD Duron Processor
Case
processtype = AMD Family
Case
processtype = K+
Case
processtype = Power PC Family
Case
processtype = Power PC
Case
processtype = Power PC
Case
processtype = Power PC +
Case
processtype = Power PC
Case
processtype = Power PC
Case
processtype = Power PC X
Case
processtype = Power PC
Case
processtype = Alpha Family
Case
processtype = Alpha
Case
processtype = Alpha
Case
processtype = Alpha
Case
processtype = Alpha PC
Case
processtype = Alpha a
Case
processtype = Alpha
Case
processtype = Alpha
Case
processtype = MIPS Family
Case
processtype = MIPS R
Case
processtype = MIPS R
Case
processtype = MIPS R
Case
processtype = MIPS R
Case
processtype = MIPS R
Case
processtype = SPARC Family
Case
processtype = SuperSPARC
Case
processtype = microSPARC II
Case
processtype = microSPARC IIep
Case
processtype = UltraSPARC
Case
processtype = UltraSPARC II
Case
processtype = UltraSPARC IIi
Case
processtype = UltraSPARC III
Case
processtype = UltraSPARC IIIi
Case
processtype =
Case
processtype = xxx Family
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype =
Case
processtype = Hobbit Family
Case
processtype = Crusoe TM Family
Case
processtype = Crusoe TM Family
Case
processtype = Weitek
Case
processtype = Itanium Processor
Case
processtype = PARISC Family
Case
processtype = PARISC
Case
processtype = PARISC
Case
processtype = PARISC LC
Case
processtype = PARISC
Case
processtype = PARISC LC
Case
processtype = PARISC
Case
processtype = V Family
Case
processtype = Pentium III Xeon
Case
processtype = Pentium III Processor with Intel SpeedStep Technology
Case
processtype = Pentium
Case
processtype = Intel Xeon
Case
processtype = AS Family
Case
processtype = Intel Xeon processor MP
Case
processtype = AMD AthlonXP Family
Case
processtype = AMD AthlonMP Family
Case
processtype = Intel Itanium
Case
processtype = AMD Opteron Family
Case
processtype = K
Case
processtype = IBM Family
Case
processtype = G
Case
processtype = G
Case
processtype = i
Case
processtype = i
Case
processtype = SH
Case
processtype = SH
Case
processtype = arm
Case
processtype = Strongarm
Case
processtype = x
Case
processtype = MediaGX
Case
processtype = MII
Case
processtype = WinChip
Case
processtype = DSP
Case
processtype = Video Processor
End Select
ListBoxItemsAdd(Family: & processtype)
End Function
Function CpuStat(ByVal CpuStNUM)
Dim stat
Select Case CpuStNUM
Case
stat = Unknown
Case
stat = CPU Enabled
Case
stat = CPU Disabled by User via BIOS Setup
Case
stat = CPU Disabled By BIOS (POST Error)
Case
stat = CPU is Idle
Case
stat = Reserved
Case
stat = Reserved
Case
stat = Other
End Select
ListBoxItemsAdd(CpuStatus: & stat)
End Function
Function processortype(ByVal proctypenum)
Dim proctype
Select Case proctypenum
Case
proctype = Other
Case
proctype = Unknown
Case
proctype = Central Processor
Case
proctype = Math Processor
Case
proctype = DSP Processor
Case
proctype = Video Processor
End Select
ListBoxItemsAdd(Processor Type: & proctype)
End Function
End Class
得到CDROM信息
Imports SystemManagement
Public Class Form
Inherits SystemWindowsFormsForm
#Region Windows 窗体设计器生成的代码
Public Sub New()
MyBaseNew()
该调用是 Windows 窗体设计器所必需的
InitializeComponent()
在 InitializeComponent() 调用之后添加任何初始化
End Sub
窗体重写 dispose 以清理组件列表
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
componentsDispose()
End If
End If
MyBaseDispose(disposing)
End Sub
Windows 窗体设计器所必需的
注意: 以下过程是 Windows 窗体设计器所必需的
可以使用 Windows 窗体设计器修改此过程
不要使用代码编辑器修改它
Private components As SystemComponentModelIContainer
Friend WithEvents ListBox As SystemWindowsFormsListBox
<SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent()
MeListBox = New SystemWindowsFormsListBox
MeSuspendLayout()
ListBox
MeListBoxLocation = New SystemDrawingPoint( )
MeListBoxName = ListBox
MeListBoxSize = New SystemDrawingSize( )
MeListBoxTabIndex =
Form
MeAutoScaleBaseSize = New SystemDrawingSize( )
MeClientSize = New SystemDrawingSize( )
MeControlsAddRange(New SystemWindowsFormsControl() {MeListBox})
MeName = Form
MeText = Form
MeResumeLayout(False)
End Sub
#End Region
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) _
Handles MyBaseLoad
On Error Resume Next
Dim SoundDeviceQuery As New SelectQuery(Win_CDROMDrive)
Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery)
Dim SoundDeviceInfo As ManagementObject
For Each SoundDeviceInfo In SoundDeviceSearchGet()
Dim SizeInMBs As Long = (Val(SoundDeviceInfo(Size)ToString()))
SizeInMBs = Int((SizeInMBs / ( * )))
ListBoxItemsAdd(CDRom Description: & SoundDeviceInfo(caption)ToString())
ListBoxItemsAdd(CDRom Manufacturer: & SoundDeviceInfo(Manufacturer)ToString())
ListBoxItemsAdd(CDRom Drive: & SoundDeviceInfo(drive)ToString())
ListBoxItemsAdd(CDRom Media Loaded: & SoundDeviceInfo(MediaLoaded)ToString())
ListBoxItemsAdd(CDRom Media Type: & SoundDeviceInfo(MediaType)ToString())
ListBoxItemsAdd(CDRom Volume Name: & SoundDeviceInfo(VolumeName)ToString())
ListBoxItemsAdd(CDRom Size: & SizeInMBs & MBytes)
ListBoxItemsAdd(CDRom Status: & SoundDeviceInfo(Status)ToString())
ListBoxItemsAdd(CDRom MaxMediaSize: & SoundDeviceInfo(MaxMediaSize)ToString())
ListBoxItemsAdd(CDRom Id: & SoundDeviceInfo(Id)ToString())
ListBoxItemsAdd(CDRom TransferRate: +Int(SoundDeviceInfo(TransferRate)ToString())+ KBs/秒)
Next
End Sub
End Class
得到硬盘信息
Imports SystemManagement
Public Class Form
Inherits SystemWindowsFormsForm
#Region Windows Form Designer generated code
Public Sub New()
MyBaseNew()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
componentsDispose()
End If
End If
MyBaseDispose(disposing)
End Sub
Private components As SystemComponentModelIContainer
Friend WithEvents ListBox As SystemWindowsFormsListBox
<SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent()
MeListBox = New SystemWindowsFormsListBox
MeSuspendLayout()
ListBox
MeListBoxLocation = New SystemDrawingPoint( )
MeListBoxName = ListBox
MeListBoxSize = New SystemDrawingSize( )
MeListBoxTabIndex =
Form
MeAutoScaleBaseSize = New SystemDrawingSize( )
MeClientSize = New SystemDrawingSize( )
MeControlsAddRange(New SystemWindowsFormsControl() {MeListBox})
MeName = Form
MeText = Form
MeResumeLayout(False)
End Sub
#End Region
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
On Error Resume Next
Dim HDDDeviceQuery As New SelectQuery(Win_DiskDrive)
Dim HDDDeviceSearch As New ManagementObjectSearcher(HDDDeviceQuery)
Dim HDDDeviceInfo As ManagementObject
For Each HDDDeviceInfo In HDDDeviceSearchGet()
ListBoxItemsAdd(HDD Description: & HDDDeviceInfo(caption)ToString())
ListBoxItemsAdd(HDD BytesPerSector: & HDDDeviceInfo(BytesPerSector)ToString())
ListBoxItemsAdd(HDD CompressionMethod: & HDDDeviceInfo(CompressionMethod)ToString())
ListBoxItemsAdd(HDD Index: & HDDDeviceInfo(Index)ToString())
ListBoxItemsAdd(HDD InstallDate: & HDDDeviceInfo(InstallDate)ToString())
ListBoxItemsAdd(HDD Manufacturer: & HDDDeviceInfo(Manufacturer)ToString())
ListBoxItemsAdd(HDD Partitions: & HDDDeviceInfo(Partitions)ToString())
ListBoxItemsAdd(HDD Size: & Int(Val(HDDDeviceInfo(Size)ToString()) / ^ ) & GBytes)
ListBoxItemsAdd(HDD TotalCylinders: & HDDDeviceInfo(TotalCylinders)ToString())
ListBoxItemsAdd(HDD TotalSectors: & HDDDeviceInfo(TotalSectors)ToString())
ListBoxItemsAdd(HDD TracksPerCylinder: & HDDDeviceInfo(TracksPerCylinder)ToString())
ListBoxItemsAdd(HDD TotalHeads: & HDDDeviceInfo(TotalHeads)ToString())
ListBoxItemsAdd(HDD TotalTracks: & HDDDeviceInfo(TotalTracks)ToString())
ListBoxItemsAdd(HDD SectorsPerTrack: & HDDDeviceInfo(SectorsPerTrack)ToString())
ListBoxItemsAdd(HDD SCSILogicalUnit: & HDDDeviceInfo(SCSILogicalUnit)ToString())
Next
End Sub
End Class
得到声卡信息
Imports SystemManagement
Public Class Form
Inherits SystemWindowsFormsForm
#Region Windows Form Designer generated code
Public Sub New()
MyBaseNew()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
componentsDispose()
End If
End If
MyBaseDispose(disposing)
End Sub
Private components As SystemComponentModelIContainer
Friend WithEvents ListBox As SystemWindowsFormsListBox
<SystemDiagnosticsDebuggerStepThrough()> Private Sub InitializeComponent()
MeListBox = New SystemWindowsFormsListBox
MeSuspendLayout()
ListBox
MeListBoxLocation = New SystemDrawingPoint( )
MeListBoxName = ListBox
MeListBoxSize = New SystemDrawingSize( )
MeListBoxTabIndex =
Form
MeAutoScaleBaseSize = New SystemDrawingSize( )
MeClientSize = New SystemDrawingSize( )
MeControlsAddRange(New SystemWindowsFormsControl() {MeListBox})
MeName = Form
MeText = Form
MeResumeLayout(False)
End Sub
#End Region
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
Dim SoundDeviceQuery As New SelectQuery(Win_SoundDevice)
Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery)
Dim SoundDeviceInfo As ManagementObject
For Each SoundDeviceInfo In SoundDeviceSearchGet()
ListBoxItemsAdd(Sound Device Description: & SoundDeviceInfo(Caption)ToString())
ListBoxItemsAdd(Sound Device Status: & SoundDeviceInfo(status)ToString())
ListBoxItemsAdd(Sound Device Manufacturer: & SoundDeviceInfo(Manufacturer)ToString())
Next
End Sub
End Class