杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2170|回复: 0

如何获得驱动器的卷标和序列号

[复制链接]
发表于 2017-1-9 20:49:10 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #ifdef Unicode
  2. #define A "W"
  3. #else
  4. #define A "A"
  5. #endif

  6. [Setup]
  7. AppName=DriveVolume
  8. AppVerName=DriveVolume
  9. Uninstallable=false
  10. UpdateUninstallLogAppName=false
  11. DisableDirPage=true
  12. DisableProgramGroupPage=true
  13. DefaultDirName={pf}\DriveVolume
  14. DisableStartupPrompt=true

  15. [_ISTool]
  16. EnableISX=true

  17. [Code]
  18. function GetVolumeInformation(
  19. lpRootPathName: String;
  20. lpVolumeNameBuffer: String;
  21. nVolumeNameSize: LongInt;
  22. var lpVolumeSerialNumber: LongInt;
  23. lpMaximumComponentLength: LongInt;
  24. lpFileSystemFlags : LongInt;
  25. lpFileSystemNameBuffer: String;
  26. nFileSystemNameSize: LongInt ) : Integer;
  27. external 'GetVolumeInformation{#A}@kernel32.dll stdcall';
  28. { // API declaration in C
  29. BOOL GetVolumeInformation(
  30.   LPCTSTR lpRootPathName,           // root directory
  31.   LPTSTR lpVolumeNameBuffer,        // volume name buffer
  32.   DWORD nVolumeNameSize,            // length of name buffer
  33.   LPDWORD lpVolumeSerialNumber,     // volume serial number
  34.   LPDWORD lpMaximumComponentLength, // maximum file name length
  35.   LPDWORD lpFileSystemFlags,        // file system options
  36.   LPTSTR lpFileSystemNameBuffer,    // file system name buffer
  37.   DWORD nFileSystemNameSize         // length of file system name buffer
  38. );
  39. }
  40. function GetLastError( ) : Integer;
  41. external 'GetLastError@kernel32.dll stdcall';

  42. function InitializeSetup(): Boolean;
  43. var srcdisk, volume: String;
  44.     ercode: Integer; sernum: LongInt;
  45. begin
  46.   Result := true;
  47.   srcdisk := AddBackslash( ExtractFileDrive( ExpandConstant('{srcexe}') ) );
  48.   volume := StringOfChar( ' ', 16 );
  49.   if GetVolumeInformation( srcdisk, volume, 15, sernum, 0, 0, '', 0 ) = 0 then
  50.     begin
  51.       ercode := GetLastError();
  52.       MsgBox( SysErrorMessage( ercode ), mbError, MB_OK );
  53.       Result := false;
  54.     end
  55.   else begin
  56.     volume := CastIntegerToString( CastStringToInteger(volume) );
  57.     MsgBox( Format( '%s 的卷标是“%s”,序列号是 %s。', [srcdisk, volume, IntToStr(sernum)] )
  58.       , mbInformation, MB_OK );
  59.   end;
  60. end;
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 18:43 , Processed in 0.115664 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表