I want to get the VB.NET or VB code to access the hard disk serial no when starting the program. It's to help me to protect my own software from people who try to pirate copies.
5 回答
在 c# 中,但你明白了。您需要为此使用 System.Management:
string driveLetter = Environment.SystemDirectory.Substring(0, 2);
string sn = new System.Management.ManagementObject("Win32_LogicalDisk.DeviceID=\"" + driveLetter + "\"").GetPropertyValue("VolumeSerialNumber").ToString();
正如其他人指出的那样,这可能不是处理此问题的最佳方法。然而,那是你的事。
I can't offer you the code, sorry, but instead I provide a warning based on my previous experience in the area.
The "Hard Disk Serial No" that was used by a number of licensing systems is actually a soft number that is written on the disk, not hardwired into the hardware.
Enterprises that used "ghosting" software to quickly churn out many desktop machines, or virtualisation software to quickly churn out many servers often had identical Hard Drive identification.
So beware if your goal is to prevent enterprises from buying one copy and using it (perhaps unintentionally) on many machines.
People often need to upgrade/replace their hard disk. Better to use the serial number from the DMI.
事实上,我使用磁盘序列号来保护我的软件。
在 vb 6.0 中,我们可以创建和使用 FileSystemObject。它允许访问硬盘驱动器的序列号,以及其他几个功能:
- 显示每个硬盘的已用和可用空间
- 创建、删除、移动文件夹
- 复制文件和文件夹
- 打印文本文件
- ... ETC。
请注意,在编写代码和声明对象之前,您必须激活
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
如果您仍然需要它,请通过 iranshahrinst@yahoo.com 或 masoodraji@aol.com 给我留言。我会把源代码发给你。
请在下面找到您问题的确切答案:
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