我希望能获取VB.NET或VB代码,在程序启动时访问硬盘序列号。这可以帮助我保护自己的软件,防止那些试图盗版的人。
我希望能获取VB.NET或VB代码,在程序启动时访问硬盘序列号。这可以帮助我保护自己的软件,防止那些试图盗版的人。
在C#中,但是你可以借鉴这个思路。你需要使用System.Management:
string driveLetter = Environment.SystemDirectory.Substring(0, 2);
string sn = new System.Management.ManagementObject("Win32_LogicalDisk.DeviceID=\"" + driveLetter + "\"").GetPropertyValue("VolumeSerialNumber").ToString();
正如其他人所指出的那样,这可能不是处理此事的最佳方式。然而,这是你的业务。
人们经常需要升级/更换硬盘。 最好使用DMI中的序列号。
事实上,我曾经使用磁盘序列号来保护我的软件。
在vb 6.0中,我们可以创建和使用FileSystemObject。它允许访问硬盘的序列号,以及其他几个功能:
请注意,在编写代码和声明对象之前,您必须激活。
Project--> References --> Microsoft Scripting Runtime
Sub ShowDriveInfo(path)
Dim fso, drv, bytesPerGB, freeGB, totalGB, s
s = ""
bytesPerGB = 1024 * 1024 * 1024
Set fso = CreateObject("Scripting.FileSystemObject")
Set drv = fso.GetDrive(fso.GetDriveName(path))
s = s & drv.Path & " - "
if drv.IsReady Then
freeGB = drv.FreeSpace / bytesPerGB
totalGB = drv.TotalSize / bytesPerGB
s = s & FormatNumber(freeGB, 3) + " GB free of "
s = s & FormatNumber(totalGB, 3) + " GB"
Else
s = s & "Not Ready"
End If
s = s & "<br />"
document.write (s)
End Sub
Function ShowDriveInfo(drvpath)
Dim fso, d, s, t
Set fso = CreateObject("Scripting.FileSystemObject")
Set d = fso.GetDrive(fso.GetDriveName(fso.GetAbsolutePathName(drvpath)))
Select Case d.DriveType
Case 0: t = "Unknown"
Case 1: t = "Removable"
Case 2: t = "Fixed"
Case 3: t = "Network"
Case 4: t = "CD-ROM"
Case 5: t = "RAM Disk"
End Select
s = "Drive " & d.DriveLetter & ": - " & t
s = s & "<BR>" & "SN: " & d.SerialNumber
ShowDriveInfo = s
End Function