小弟正在学VC++,请问怎样用API函数来获得硬盘的序列号,请详细说明好吗?谢谢

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc.asp?id=706
      

  2.   

    The GetVolumeInformation function retrieves information about a file system and volume whose root directory is specified. BOOL GetVolumeInformation(
      LPCTSTR lpRootPathName,           // root directory
      LPTSTR lpVolumeNameBuffer,        // volume name buffer
      DWORD nVolumeNameSize,            // length of name buffer
      LPDWORD lpVolumeSerialNumber,     // volume serial number
      LPDWORD lpMaximumComponentLength, // maximum file name length
      LPDWORD lpFileSystemFlags,        // file system options
      LPTSTR lpFileSystemNameBuffer,    // file system name buffer
      DWORD nFileSystemNameSize         // length of file system name buffer
    );
    Parameters
    lpRootPathName 
    [in] Pointer to a string that contains the root directory of the volume to be described. If this parameter is NULL, the root of the current directory is used. A trailing backslash is required. For example, you would specify \\MyServer\MyShare as \\MyServer\MyShare\, or the C drive as "C:\". 
    lpVolumeNameBuffer 
    [out] Pointer to a buffer that receives the name of the specified volume. 
    nVolumeNameSize 
    [in] Specifies the length, in TCHARs, of the volume name buffer. This parameter is ignored if the volume name buffer is not supplied. 
    lpVolumeSerialNumber 
    [out] Pointer to a variable that receives the volume serial number. This parameter can be NULL if the serial number is not required. 
    Windows 95/98/Me: If the queried volume is a network drive, the serial number will not be returned. lpMaximumComponentLength 
    [out] Pointer to a variable that receives the maximum length, in TCHARs, of a file name component supported by the specified file system. A file name component is that portion of a file name between backslashes. 
    The value stored in variable pointed to by *lpMaximumComponentLength is used to indicate that long names are supported by the specified file system. For example, for a FAT file system supporting long names, the function stores the value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the NTFS file system. lpFileSystemFlags 
    [out] Pointer to a variable that receives flags associated with the specified file system. This parameter can be any combination of the following flags; however, FS_FILE_COMPRESSION and FS_VOL_IS_COMPRESSED are mutually exclusive. Value Meaning 
    FS_CASE_IS_PRESERVED The file system preserves the case of file names when it places a name on disk. 
    FS_CASE_SENSITIVE The file system supports case-sensitive file names. 
    FS_UNICODE_STORED_ON_DISK The file system supports Unicode in file names as they appear on disk. 
    FS_PERSISTENT_ACLS The file system preserves and enforces ACLs. For example, NTFS preserves and enforces ACLs, and FAT does not.  
    FS_FILE_COMPRESSION The file system supports file-based compression. 
    FS_VOL_IS_COMPRESSED The specified volume is a compressed volume; for example, a DoubleSpace volume. 
    FILE_NAMED_STREAMS The file system supports named streams. 
    FILE_READ_ONLY_VOLUME Whistler: The specified volume is read-only. 
    FILE_SUPPORTS_ENCRYPTION The file system supports the Encrypted File System (EFS). 
    FILE_SUPPORTS_OBJECT_IDS The file system supports object identifiers. 
    FILE_SUPPORTS_REPARSE_POINTS The file system supports reparse points. 
    FILE_SUPPORTS_SPARSE_FILES The file system supports sparse files. 
    FILE_VOLUME_QUOTAS The file system supports disk quotas. 
    lpFileSystemNameBuffer 
    [out] Pointer to a buffer that receives the name of the file system (such as FAT or NTFS). 
    nFileSystemNameSize 
    [in] Specifies the length, in TCHARs, of the file system name buffer. This parameter is ignored if the file system name buffer is not supplied. 
    如果只想得到序列号,则
    DWORD m_applycode;
    GetVolumeInformation("c:",0,0,&m_applycode,0,0,0,0);
    就可以了