2008-11-26 62 views
3

我想在啓動程序時獲取VB.NET或VB代碼來訪問硬盤序列號。這是爲了幫助我保護我自己的軟件免受試圖盜版副本的人的影響。通過訪問硬盤序列號來保護軟件

+1

太苛刻了,查爾斯?我把它當作尋求幫助來找到操作系統調用來獲取這些信息。 – Oddthinking 2008-11-26 01:43:40

回答

2

人們經常需要升級/更換硬盤。 更好地使用來自DMI的序列號。

3

我不能爲您提供代碼,對不起,但我提供了一個基於我以前在該地區的經驗的警告。

許多許可系統使用的「硬盤序列號」實際上是寫在磁盤上的軟數字,而不是硬連線到硬件中。

使用「重影」軟件快速生成許多臺式機或使用虛擬化軟件快速生成大量服務器的企業通常具有相同的硬盤驅動器標識。

所以要小心,如果你的目標是防止企業購買一個副本,並在許多機器上使用它(可能是無意的)。

7

在c#中,但你明白了。您需要爲此使用System.Management:

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

正如其他人指出的,這可能不是處理此問題的最佳方法。但是,這是你的事。

1

事實上,我已經使用磁盤序列號來保護我的軟件。

在vb 6.0中,我們可以創建和使用FileSystemObject。它允許訪問硬盤驅動器的序列號,以及其他幾個功能:

  • 顯示每個硬盤
  • 創建,刪除的使用和可用空間,移動文件夾
  • 複製文件和文件夾
  • 打印文本文件
  • ...等

注意,編寫代碼,並聲明該對象之前,您必須ACTIVAT e

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 

如果您仍需要它,請在[email protected][email protected]下降了一張字條給我。我會給你發送源代碼。

0

請在下面找到確切的回答你的問題:

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