杉宫竹苑工作室

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

Inno Setup 实现安装界面显示MAC与硬盘地址

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

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

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

x

显示MAC网卡地址
  1. [Setup]
  2. AppName=My Program
  3. AppVersion=1.5
  4. DefaultDirName={pf}My Program
  5. DefaultGroupName=My Program

  6. [Files]
  7. Source: "ISID.dll"; Flags: dontcopy

  8. [Code]
  9. function GetMACAddress(output: String): Integer;
  10. external 'GetMACAddress@files:ISID.dll stdcall';

  11. function GetMacAdd: string;
  12. var
  13.   ClassName: String;
  14.   Ret: Integer;
  15. begin
  16.   SetLength(ClassName, 256);
  17.   Ret := GetMacAddress(PChar(ClassName));
  18.   Result := Copy(ClassName, 1 , Ret);
  19. end;

  20. procedure InitializeWizard();
  21. var
  22.   labMacAdd: TLabel;
  23. begin
  24.   WizardForm.WelcomeLabel2.Height := ScaleY(200);
  25.   labMacAdd := TLabel.Create(WizardForm);
  26.   with labMacAdd do
  27.   begin
  28.     Parent := WizardForm.WelcomePage;
  29.     Caption := 'MAC 地址: ' + GetMacAdd;
  30.     Transparent := False;
  31.     Left := ScaleX(174);
  32.     Top := ScaleY(280);
  33.     Width := ScaleX(120);
  34.     Height := ScaleY(12);
  35.   end;
  36. end;
复制代码
48_377_189730bd6d8c53d.gif

变种,下面的代码即适合 Unicode 版本,也适合 ANSI 版本,都可以正确显示 MAC 地址。
  1. #ifdef Unicode
  2. #define PChar "PAnsiChar"
  3. #define String "AnsiString"
  4. #else
  5. #define PChar "PChar"
  6. #define String "String"
  7. #endif

  8. [Setup]
  9. AppName=My Program
  10. AppVersion=1.5
  11. DefaultDirName={pf}My Program
  12. DefaultGroupName=My Program

  13. [Files]
  14. Source: "ISID.dll"; Flags: dontcopy

  15. [Code]
  16. function GetMACAddress(output: {#String}): Integer;
  17. external 'GetMACAddress@files:ISID.dll stdcall';

  18. function GetMacAdd: string;
  19. var
  20.   ClassName: {#String};
  21.   Ret: Integer;
  22. begin
  23.   SetLength(ClassName, 256);
  24.   Ret := GetMacAddress({#PChar}(ClassName));
  25.   Result := Copy(ClassName, 1 , Ret);
  26. end;

  27. procedure InitializeWizard();
  28. var
  29.   labMacAdd: TLabel;
  30. begin
  31.   WizardForm.WelcomeLabel2.Height := ScaleY(200);
  32.   labMacAdd := TLabel.Create(WizardForm);
  33.   with labMacAdd do
  34.   begin
  35.     Parent := WizardForm.WelcomePage;
  36.     Caption := 'MAC 地址: ' + Uppercase(GetMACAdd);
  37.     Transparent := False;
  38.     Left := ScaleX(174);
  39.     Top := ScaleY(280);
  40.     Width := ScaleX(300);
  41.     Height := ScaleY(14);
  42.   end;
  43. end;
复制代码
获取硬盘序列号如下
  1. #ifdef Unicode
  2. #define PChar "PAnsiChar"
  3. #define String "AnsiString"
  4. #else
  5. #define PChar "PChar"
  6. #define String "String"
  7. #endif

  8. [Setup]
  9. AppName=My Program
  10. AppVersion=1.5
  11. DefaultDirName={pf}My Program
  12. DefaultGroupName=My Program

  13. [Files]
  14. Source: "{tmp}ISID.dll"; Flags: dontcopy

  15. [Code]

  16. function GetHDDSerial(Drive: Char; output: String):Integer;external 'GetHDDSerial@files:ISID.dll stdcall';



  17. function GetHDD: string;//获取硬盘序列号函数
  18. var
  19.   ClassName: {#String};
  20.   Ret: Integer;
  21.   f: Char;
  22.   
  23. begin
  24.   SetLength(ClassName, 256);
  25.   Ret := GetHDDSerial(f,{#PChar}(ClassName));
  26.   Result := Copy(ClassName, 1 , Ret);
  27. end;


  28. procedure InitializeWizard();
  29. var
  30.   labMacAdd: TLabel;
  31. begin
  32.   WizardForm.WelcomeLabel2.Height := ScaleY(200);
  33.   labMacAdd := TLabel.Create(WizardForm);
  34.   with labMacAdd do
  35.   begin
  36.     Parent := WizardForm.WelcomePage;
  37.     Caption := '硬盘序列号: ' + Uppercase(GetHDD);  //显示MAC地址并转换为大写字母(Uppercase转换为大写字母)
  38.     Transparent := False;
  39.     Left := ScaleX(174);
  40.     Top := ScaleY(280);
  41.     Width := ScaleX(300);
  42.     Height := ScaleY(14);
  43.   end;
  44. end;
复制代码
48_222436_a4b8ab76bb509e7.jpg




回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-19 18:47 , Processed in 0.131811 second(s), 24 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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