gpt4 book ai didi

.net - 有没有更快的方法来获取卷序列号?

转载 作者:行者123 更新时间:2023-12-03 01:52:55 25 4
gpt4 key购买 nike

您好,我正在使用此代码来生成机器签名。但执行起来需要相当长的时间。想知道为什么这么慢?有什么更快的方法推荐吗?

Public Shared Function DriveSN(ByVal DriveLetter As String) As String
Dim disk As ManagementObject = New ManagementObject(String.Format("Win32_Logicaldisk='{0}'", DriveLetter))
Dim VolumeName As String = disk.Properties("VolumeName").Value.ToString()
Dim SerialNumber As String = disk.Properties("VolumeSerialnumber").Value.ToString()
Return SerialNumber.Insert(4, "-")
End Function

Private Shared msig As String = Nothing

Public Shared Function MachineSignature() As String
If msig Is Nothing Then
Dim list As New List(Of String)
For Each d As DriveInfo In DriveInfo.GetDrives()
If (d.IsReady) Then
list.Add(DriveSN(d.Name.Substring(0, 2)))
End If
Next
msig = String.Join(" & ", list.ToArray())
End If
Return msig
End Function

最佳答案

egghead cafe 也有一种 .Net 方式使用 System.Management 命名空间。

首先,您需要在vb.net中添加对System.Management dll的引用。使用“项目”->“添加引用”菜单项。

然后以下代码获取C盘的驱动器序列号:

Dim drive As String = "C"
Dim disk As System.Management.ManagementObject = _
New System.Management.ManagementObject _
("win32_logicaldisk.deviceid=""" + drive + ":""")
disk.Get()
Dim SerialNumber as String = disk("VolumeSerialNumber").ToString()

关于.net - 有没有更快的方法来获取卷序列号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1142579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com