田草博客

互联网田草博客


网友交流QQ群:11740834 需注明申请加入原因

微信 公众号:ByCAD

邮箱:tiancao1001x126.com
ByCAD,微信公众号
首页 | 普通 | 电脑 | AutoCAD | VB/VB.NET | FLash | 结构 | 建筑 | 电影 | BIM | 规范 | 软件 | ID
-随机-|-分布-
-博客论坛-|-﨣﨤﨧﨨-
-网站导航-|-规范下载-
-BelovedFLash欣赏-

用户登陆
用户:
密码:
 

站点日历
73 2024 - 4 48
 123456
78910111213
14151617181920
21222324252627
282930


站点统计

最新评论



VB.Net遍历文件夹及文件操作 vb.net 删除IE历史记录和临时文件
未知 VB.NET中得到计算机硬件信息   [ 日期:2010-11-25 ]   [ 来自:转帖 ]  HTML
一、得到显示器分辨率

Dim X As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
Dim Y As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
MsgBox("您的显示器分辨率是:" & X & " X " & Y)


二、得到特殊文件夹的路径

'"Desktop"桌面文件夹路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
'"Favorites"收藏夹路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.Favorites))
'"Application Data"路径
MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))

'通用写法
'Dim SPEC As String = Environment.GetFolderPath(Environment.SpecialFolder.XXXXXXX)
'XXXXXXX是特殊文件夹的名字


三、得到操作系统版本信息

MsgBox(Environment.OSVersion.ToString)
得到当前登录的用户名
MsgBox(Environment.UserName)
得到当前应用程序的路径
MsgBox(Environment.CurrentDirectory)


四、打开和关闭CD-ROM

'先新建模块
Module mciAPIModule
Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
End Module
'打开CD-ROM
Dim lRet As Long
lRet = mciSendString("set cdAudio door open", 0&, 0, 0)
关闭CD-ROM
Dim lRet As Long
lRet = mciSendString("set cdAudio door Closed", 0&, 0, 0)


五、得到计算机IP和计算机全名

Dim MYIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
MsgBox("您的IP地址:" & (MYIP.AddressList.GetValue(0).ToString))
MsgBox("您的计算机全名:" & (MYIP.HostName.ToString))
使用win32_operatingSystem (wmi Class)得到计算机信息 
'添加ListBox在Form1_Load事件里,并引用system.Managment
Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
Dim opInfo As ManagementObject
For Each opInfo In opSearch.Get()
ListBox1.Items.Add("Name: " & opInfo("name").ToString())
ListBox1.Items.Add("Version: " & opInfo("version").ToString())
ListBox1.Items.Add("Manufacturer: " & opInfo("manufacturer").ToString())
ListBox1.Items.Add("Computer name: " & opInfo("csname").ToString())
ListBox1.Items.Add("Windows Directory: " & opInfo("windowsdirectory").ToString())
Next


六、列出计算机安装的全部字体,并添加到ListBox

'新建Form并添加ListBox和Button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fntCollection As InstalledFontCollection = New InstalledFontCollection()
Dim fntFamily() As FontFamily
fntFamily = fntCollection.Families
ListBox1.Items.Clear()
Dim i As Integer = 0
For i = 0 To fntFamily.Length - 1 
ListBox1.Items.Add(fntFamily(i).Name)
Next
End Sub

七、得到CD-ROM信息

Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Private components As System.ComponentModel.IContainer
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(24, 16)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(416, 173)
Me.ListBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 206)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
On Error Resume Next
Dim SoundDeviceQuery As New SelectQuery("Win32_CDROMDrive")
Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery)
Dim SoundDeviceInfo As ManagementObject
For Each SoundDeviceInfo In SoundDeviceSearch.Get()
Dim SizeInMBs As Long = (Val(SoundDeviceInfo("Size").ToString()))
SizeInMBs = Int((SizeInMBs / (1024 * 1024)))
ListBox1.Items.Add("CD-Rom Description: " & SoundDeviceInfo("caption").ToString())
ListBox1.Items.Add("CD-Rom Manufacturer: " & SoundDeviceInfo("Manufacturer").ToString())
ListBox1.Items.Add("CD-Rom Drive: " & SoundDeviceInfo("drive").ToString())
ListBox1.Items.Add("CD-Rom Media Loaded: " & SoundDeviceInfo("MediaLoaded").ToString())
ListBox1.Items.Add("CD-Rom Media Type: " & SoundDeviceInfo("MediaType").ToString())
ListBox1.Items.Add("CD-Rom Volume Name: " & SoundDeviceInfo("VolumeName").ToString())
ListBox1.Items.Add("CD-Rom Size: " & SizeInMBs & " MBytes")
ListBox1.Items.Add("CD-Rom Status: " & SoundDeviceInfo("Status").ToString())
ListBox1.Items.Add("CD-Rom MaxMediaSize: " & SoundDeviceInfo("MaxMediaSize").ToString())
ListBox1.Items.Add("CD-Rom Id: " & SoundDeviceInfo("Id").ToString())
ListBox1.Items.Add("CD-Rom TransferRate: "+Int(SoundDeviceInfo("TransferRate").ToString())+" KBs/秒")
Next
End Sub
End Class

八、得到硬盘信息

Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(8, 8)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(272, 212)
Me.ListBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 238)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

On Error Resume Next
Dim HDDDeviceQuery As New SelectQuery("Win32_DiskDrive")
Dim HDDDeviceSearch As New ManagementObjectSearcher(HDDDeviceQuery)
Dim HDDDeviceInfo As ManagementObject
For Each HDDDeviceInfo In HDDDeviceSearch.Get()
ListBox1.Items.Add("HDD Description: " & HDDDeviceInfo("caption").ToString())
ListBox1.Items.Add("HDD BytesPerSector: " & HDDDeviceInfo("BytesPerSector").ToString())
ListBox1.Items.Add("HDD CompressionMethod: " & HDDDeviceInfo("CompressionMethod").ToString())
ListBox1.Items.Add("HDD Index: " & HDDDeviceInfo("Index").ToString())
ListBox1.Items.Add("HDD InstallDate: " & HDDDeviceInfo("InstallDate").ToString())
ListBox1.Items.Add("HDD Manufacturer: " & HDDDeviceInfo("Manufacturer").ToString())
ListBox1.Items.Add("HDD Partitions: " & HDDDeviceInfo("Partitions").ToString())
ListBox1.Items.Add("HDD Size: " & Int(Val(HDDDeviceInfo("Size").ToString()) / 2 ^ 30) & " GBytes")
ListBox1.Items.Add("HDD TotalCylinders: " & HDDDeviceInfo("TotalCylinders").ToString())
ListBox1.Items.Add("HDD TotalSectors: " & HDDDeviceInfo("TotalSectors").ToString())
ListBox1.Items.Add("HDD TracksPerCylinder: " & HDDDeviceInfo("TracksPerCylinder").ToString())
ListBox1.Items.Add("HDD TotalHeads: " & HDDDeviceInfo("TotalHeads").ToString())
ListBox1.Items.Add("HDD TotalTracks: " & HDDDeviceInfo("TotalTracks").ToString())
ListBox1.Items.Add("HDD SectorsPerTrack: " & HDDDeviceInfo("SectorsPerTrack").ToString())
ListBox1.Items.Add("HDD SCSILogicalUnit: " & HDDDeviceInfo("SCSILogicalUnit").ToString())
Next
End Sub
End Class


九、得到声卡信息

Imports System.Management
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point(8, 8)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(272, 212)
Me.ListBox1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 238)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SoundDeviceQuery As New SelectQuery("Win32_SoundDevice")
Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery)
Dim SoundDeviceInfo As ManagementObject
For Each SoundDeviceInfo In SoundDeviceSearch.Get()
ListBox1.Items.Add("Sound Device Description: " & SoundDeviceInfo("Caption").ToString())
ListBox1.Items.Add("Sound Device Status: " & SoundDeviceInfo("status").ToString())
ListBox1.Items.Add("Sound Device Manufacturer: " & SoundDeviceInfo("Manufacturer").ToString())
Next
End Sub

End Class


程序代码:

Namespace ComputerID
    Public Class Computer
        Public Shared _cpu_id As String
        Public Shared ReadOnly Property CPU_ID() As String
            Get
                If _cpu_id Is Nothing Then
                    Try
                        _cpu_id = String.Empty
                        Using enumerator As ManagementObjectCollection.ManagementObjectEnumerator = New ManagementClass("win32_processor").GetInstances().GetEnumerator()
                            While enumerator.MoveNext()
                                Dim managementObject As ManagementObject = CType(enumerator.Current, ManagementObject)
                                _cpu_id = managementObject.Properties("ProcessorID").Value.ToString()
                                If Not (_cpu_id = String.Empty) Then
                                    Exit While
                                End If
                            End While
                        End Using
                    Catch ex As ApplicationException
                        Throw New ApplicationException("无法检索到CPU序列号。", ex)
                    End Try
                End If
                Return _cpu_id
            End Get
        End Property
    End Class
End Namespace


[本日志由 tiancao1001 于 2023-11-22 11:03 PM 编辑]


暂时没有评论
发表评论 - 不要忘了输入验证码哦!
作者: 用户:  密码:   注册? 验证:  防止恶意留言请输入问题答案:2*6=?  
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字

字体样式 文字大小 文字颜色
插入粗体文本 插入斜体文本 插入下划线
左对齐 居中对齐 右对齐
插入超级链接 插入邮件地址 插入图像
插入 Flash 插入代码 插入引用
插入列表 插入音频文件 插入视频文件
插入缩进符合
点击下载按钮 下标 上标
水平线 简介分割标记
表  情
 
Tiancao Blog All Rights Reserved 田草博客 版权所有
Copyright ©