VB.NET中有一个特点就是对移动设备的操作。运用这一语言可以对这些设备进行满足我们需求的操作。比如获取硬盘的序列号等等。要实现VB.NET硬盘序列号的获取,需要访问注册表.实际操作如下,建立一个新的窗体,在上面添加一个标签Label1,一个按钮Command1,实现:按下按钮,在标签上显示硬盘序列号.#t#
代码:
- Imports system
- Imports Microsoft.Win32
- Imports system.Diagnostics
- Imports system.Windows.Forms
以上创建命名空间
- Private Command1_Click
(ByVal sender As System.Object,_ - ByVal e As System.EventArgs)
Handles Command1.Click - Dim myDec As RegistryKey
- Dim myScsi As RegistryKey
- Dim myPort As RegistryKey
- Dim myBus As RegistryKey
- Dim myHd As RegistryKey
- Dim myInfo As RegistryKey
- Dim myHW As RegistryKey
- Dim myLM As RegistryKey
定义获取硬盘序列号的节点
- myLM=Registry.LocalMachine
- myHW=myLM.OpenSubKey("HARDWARE")
- myDec=myHW.OpenSubKey("DEVICEMAP")
- myScsi=myDec.OpenSubKey("Scsi")
- myPort=myScsi.OpenSubKey
("Scsi Port 1")- myBus=myPort.OpenSubKey
("Scsi Bus 0")- myHd=myBus.OpenSubKey
("Target Id 0")- myInfo=myHd.OpenSubKey
("Logical Unit Id 0")
VB.NET硬盘序列号的获取
- Me.Label1.Text=
myInfo.GetValue
("Identifier")
在标签上将VB.NET硬盘序列号的结果显示出来