程序代码: | [ 复制代码到剪贴板 ] |
Imports System.Management
Public Class Form1
'获取硬盘ID
Public Function GetMainHardDiskId() As String
Dim Result As String = ""
Dim mClass As ManagementClass = New ManagementClass("Win32_PhysicalMedia")
Dim moCollection As ManagementObjectCollection = mClass.GetInstances()
For Each mObject As ManagementObject In moCollection
Result = mObject("SerialNumber").ToString
Next
Return Result
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'获取硬盘ID
MsgBox(GetMainHardDiskId())
End Sub
End Class
Public Class Form1
'获取硬盘ID
Public Function GetMainHardDiskId() As String
Dim Result As String = ""
Dim mClass As ManagementClass = New ManagementClass("Win32_PhysicalMedia")
Dim moCollection As ManagementObjectCollection = mClass.GetInstances()
For Each mObject As ManagementObject In moCollection
Result = mObject("SerialNumber").ToString
Next
Return Result
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'获取硬盘ID
MsgBox(GetMainHardDiskId())
End Sub
End Class
不仅可以获得硬盘ID还可以:
Capacity
Caption
CleanerMedia
CreationClassName
Description
HotSwappable
InstallDate
Manufacturer
MediaDescription
MediaType
Model
Name
OtherIdentifyingInfo
PartNumber
PoweredOn
Removable
Replaceable
SerialNumber
SKU
Status
Tag
Version
WriteProtectOn
Caption
CleanerMedia
CreationClassName
Description
HotSwappable
InstallDate
Manufacturer
MediaDescription
MediaType
Model
Name
OtherIdentifyingInfo
PartNumber
PoweredOn
Removable
Replaceable
SerialNumber
SKU
Status
Tag
Version
WriteProtectOn
以上各属性,不一定都能用上面的代码获得,可能要修改代码。
程序代码: |
'获取主板序列号
Public Function GetBIOSSerialNumbr() As String
Try
Dim searcher As New ManagementObjectSearcher("Select * From Win32_BIOS")
Dim sBIOSSerialNumber As String = ""
For Each mo As ManagementObject In searcher.[Get]()
sBIOSSerialNumber = mo("SerialNumber").ToString().Trim()
Next
Return sBIOSSerialNumber
Catch
Return ""
End Try
End Function
'获取CPU序列号
Public Function GetCPUSerialNumber() As String
Try
Dim searcher As New ManagementObjectSearcher("Select * From Win32_Processor")
Dim sCPUSerialNumber As String = ""
For Each mo As ManagementObject In searcher.[Get]()
sCPUSerialNumber = mo("ProcessorId").ToString().Trim()
Next
Return sCPUSerialNumber
Catch
Return ""
End Try
End Function
'获取硬盘序列号
Public Function GetHardDiskSerialNumber() As String
Try
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")
Dim sHardDiskSerialNumber As String = ""
For Each mo As ManagementObject In searcher.[Get]()
sHardDiskSerialNumber = mo("SerialNumber").ToString().Trim()
Exit For
Next
Return sHardDiskSerialNumber
Catch
Return ""
End Try
End Function
'获取网卡地址
Public Function GetNetCardMACAddress() As String
Try
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> ‘Microsoft‘))")
Dim NetCardMACAddress As String = ""
For Each mo As ManagementObject In searcher.[Get]()
NetCardMACAddress = mo("MACAddress").ToString().Trim()
Next
Return NetCardMACAddress
Catch
Return ""
End Try
End Function
c#获取电脑硬件信息参数说明( Win32_PhysicalMedia )
Caption 物理内存还虚拟内存
Description 描述和Caption一样
InstallDate 安装日期(无值)
Name 名字
Status 状态
CreationClassName 创建类名(就是更换这个类的名字)
Manufacturer 生产商
Model 型号
SKU SKU号
SerialNumber 编号
Tag 唯一标识符的物理存储器
Version 版本信息
PartNumber 零件编号
OtherIdentifyingInfo 其他识别信息
PoweredOn 是否接通电源
Removable 是否可拆卸
Replaceable 是否可更换
HotSwappable 是否支持热插拔
Capacity 获取内存容量(单位KB)
MediaType
MediaDescription
WriteProtectOn 写保护开
CleanerMedia
经验证:
1、使用wmi获取的cpuid并不是唯一的,同一种型号的cpu通过wmi获取是一样的,而且不会因系统的重装而改变
2、因为Win32_DiskDrive的“PNPDeviceID”,可以获取所有的驱动器的型号及相关参数,不同硬盘参数唯一,而且不会因系统重装而改变(此属性不能用于iis中的网页文件,应采用下面的)
Private Sub Command1_Click()
Text1.Text = GetHdId
End Sub
Function GetHdId()
Dim Hdid
WQL = "SELECT * FROM Win32_DiskDrive"
Set objinst = GetObject("winmgmts:").ExecQuery(WQL)
For Each obj In objinst
If IsNull(obj.DeviceID) Then
Hdid = "no disk "
Else
If Hdid <> "" Then
Hdid = Hdid + " 下一个:"
End If
Hdid = Hdid + CStr(obj.PNPDeviceID)
End If
Next
GetHdId = Hdid
End Function
3、Signature属性获得的值为一负数,经测试重装系统此参数保持不变,并且具有唯一性,此属性不能用于网页
https://blog.csdn.net/polloo2012/article/details/79408072
/// <summary>
/// 获取传感器ID(16位HASH代码)
/// </summary>
/// <returns></returns>
private static string GetSensorID()
{
string sensorID = string.Empty;
string basicID = GetCPUID() + GetMotherboardID() + GetPhysicalMemoryID();
System.Security.Cryptography.MD5CryptoServiceProvider mD5CryptoServiceProvider = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hashedBuff = mD5CryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(basicID));
for (int i = 4; i < 12; i++)
{
sensorID += hashedBuff[i].ToString("X2");
}
return sensorID;
}
/// <summary>
/// 获得cpu序列号
/// </summary>
/// <returns></returns>
private static string GetCPUID()
{
var myCpu = new ManagementClass("win32_Processor").GetInstances();
var serial = "";
foreach (ManagementObject cpu in myCpu)
{
var val = cpu.Properties["Processorid"].Value;
serial += val == null ? "" : val.ToString();
}
return serial;
}
/// <summary>
/// 获取主板序列号
/// </summary>
/// <returns></returns>
private static string GetMotherboardID()
{
var myMb = new ManagementClass("Win32_BaseBoard").GetInstances();
var serial = "";
foreach (ManagementObject mb in myMb)
{
var val = mb.Properties["SerialNumber"].Value;
serial += val == null ? "" : val.ToString();
}
return serial;
}
/// <summary>
/// 获取所有内存信息,参考 CPUID 软件
/// </summary>
/// <returns></returns>
private static string GetPhysicalMemoryID()
{
string memoryID = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_PhysicalMemory");
foreach (var prop in mos.Get())
{
memoryID = memoryID + prop["PartNumber"].ToString().Trim() + prop["SerialNumber"].ToString().Trim();
}
return memoryID;
[本日志由 tiancao1001 于 2019-11-21 03:22 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |