2012-02-27 60 views

回答

2

在VB

試試這個代碼
Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long 
Private Sub Form_Load() 
    Dim Serial As Long 
    'Get the volume information 
    GetVolumeInformation "d:\", vbNullString, 255, Serial, 0, 0, vbNullString, 255 

    MsgBox Hex(Serial) 
End Sub 

這應該作爲一個概念證明爲你。您可以根據自己選擇的語言進行調整。

從這裏摘自:VB Forums

+0

感謝您的回答。我只想確定檢索到的'Serial'是OS獨立的,是這樣或者它只是Windows計算的特定哈希? – menjaraz 2012-02-27 08:45:24

+0

CD-ROM確實有一個序列號。它獨立於操作系統 – 2012-02-27 08:46:43

+0

再次感謝您。我接受你的答案,我會嘗試做一個德爾福的端口並在稍後發佈。我在Q中添加了一個[tag:language-agnostic]標籤。希望其他語言的實現(答案)會在這裏發佈。 – menjaraz 2012-02-27 08:51:20

1

Windows.GetVolumeInformation語法

GetVolumeInformation(
    lpRootPathName: PChar; {the path to the root directory} 
    lpVolumeNameBuffer: PChar; {the buffer receiving the volume name} 
    nVolumeNameSize: DWORD; {the maximum size of the buffer} 
    lpVolumeSerialNumber: PDWORD; {a pointer to the volume serial number} 
    var lpMaximumComponentLength: DWORD; {maximum file component name} 
    var lpFileSystemFlags: DWORD; {file system flags} 
    lpFileSystemNameBuffer: PChar; {the buffer receiving the file system name} 
    nFileSystemNameSize: DWORD {the maximum size of the file system name} 
): BOOL; {returns TRUE or FALSE} 

德爾福端口(略改編自Andrei G的帖子)

GetCDROMSerial片段:

用法示例:

ShowMessage(Format('%X', [GetCDROMSerial('F')])); 
+0

這是我的德爾福港安德烈的答案(與德爾福XE測試)。 – menjaraz 2012-02-27 09:41:32