To protect software by accessing harddisk serial no [closed]

北战南征 提交于 2019-12-06 06:57:12

问题


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.


回答1:


In c#, but you get the idea. You'll want to use System.Management for this:

string driveLetter = Environment.SystemDirectory.Substring(0, 2);
string sn = new System.Management.ManagementObject("Win32_LogicalDisk.DeviceID=\"" + driveLetter + "\"").GetPropertyValue("VolumeSerialNumber").ToString();

As others have pointed out, this might not be the best way to handle this. However, that's your business.




回答2:


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.




回答3:


People often need to upgrade/replace their hard disk. Better to use the serial number from the DMI.




回答4:


In fact I have used disk serial number for protecting my softwares.

In vb 6.0, we can create and use FileSystemObject. It allows accessing the hard drives' serial numbers, plus several other functions:

  • displaying the used and free space of each hard disk
  • Creating, Deleting, moving folders
  • copying files and folders
  • printing text files
  • ... etc.

Note that prior to writing the code and declaring the object you must activate

Project--> References --> Microsoft Scripting Runtime

The following code extracts some info about the drive but you can also extract the serial number of the drive.

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

If you still need it, please drop a note to me at iranshahrinst@yahoo.com or masoodraji@aol.com. I'll send you the source code.




回答5:


Please find below the exact answer to your question:

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


来源:https://stackoverflow.com/questions/319508/to-protect-software-by-accessing-harddisk-serial-no

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!