2012-02-27 58 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