杉宫竹苑工作室

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

如何获得驱动器类型

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

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

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

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

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

  15. [Code]
  16. function GetDriveType( lpDisk: String ): Integer;
  17. external 'GetDriveType{#A}@kernel32.dll stdcall';
  18. const
  19.   DRIVE_UNKNOWN = 0; // The drive type cannot be determined.
  20.   DRIVE_NO_ROOT_DIR = 1; // The root path is invalid. For example, no volume is mounted at the path.
  21.   DRIVE_REMOVABLE = 2; // The disk can be removed from the drive.
  22.   DRIVE_FIXED = 3; // The disk cannot be removed from the drive.
  23.   DRIVE_REMOTE = 4; // The drive is a remote (network) drive.
  24.   DRIVE_CDROM = 5; // The drive is a CD-ROM drive.
  25.   DRIVE_RAMDISK = 6; // The drive is a RAM disk.

  26. // function to convert disk type to string
  27. function DriveTypeString( dtype: Integer ): String;
  28. begin
  29.   case dtype of
  30.     DRIVE_NO_ROOT_DIR : Result := '根目录无效';  //'Root path invalid';
  31.     DRIVE_REMOVABLE : Result := '可移动盘';      //'Removable';
  32.     DRIVE_FIXED : Result := '硬盘';              //'Fixed';
  33.     DRIVE_REMOTE : Result := '网络';             //'Network';
  34.     DRIVE_CDROM : Result := '光盘';              //'CD-ROM';
  35.     DRIVE_RAMDISK : Result := '内存';            //'Ram disk';
  36.   else
  37.     Result := '未知';                            //'Unknown';
  38.   end;
  39. end;

  40. function InitializeSetup(): Boolean;
  41. var srcdisk: String;
  42.     disktype: Integer;
  43. begin
  44.   Result := true;
  45.   // get drive from where setup was launched
  46.   srcdisk := AddBackSlash( ExtractFileDrive( ExpandConstant('{srcexe}') ) ) ;
  47.   // get number type of disk
  48.   disktype := GetDriveType( srcdisk );
  49.   // show which type of disk it is
  50.   MsgBox( Format( '安装程序从 %s 启动,类型为“%s”。', [srcdisk, DriveTypeString( disktype )] ) , mbInformation, MB_OK );
  51. end;
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 20:31 , Processed in 0.108206 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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