加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

winapi – 如何在Inno Setup中使用GetVolumeInformation?

发布时间:2020-12-15 04:31:44 所属栏目:大数据 来源:网络整理
导读:在使用Inno Setup创建的安装过程中,我需要获取驱动器号的卷序列号.我知道DLL函数可以导入Inno,但我对它很新,并且在使它工作时遇到一些问题.我知道kernel32中的GetVolumeInformation函数可以做我需要的.有人可以告诉我如何在Inno脚本中导入和使用该功能来检索
在使用Inno Setup创建的安装过程中,我需要获取驱动器号的卷序列号.我知道DLL函数可以导入Inno,但我对它很新,并且在使它工作时遇到一些问题.我知道kernel32中的GetVolumeInformation函数可以做我需要的.有人可以告诉我如何在Inno脚本中导入和使用该功能来检索卷序列号吗?

谢谢!

解决方法

Inno-Setup代码::
[Code]
function GetVolumeInformation(
  lpRootPathName: PChar;
  lpVolumeNameBuffer: PChar;
  nVolumeNameSize: DWORD;
  var lpVolumeSerialNumber: DWORD;
  var lpMaximumComponentLength: DWORD;
  var lpFileSystemFlags: DWORD;
  lpFileSystemNameBuffer: PChar;
  nFileSystemNameSize: DWORD
  ): BOOL;
  external 'GetVolumeInformationA@kernel32.dll stdcall';


function LoWord(dw: DWORD): WORD;
begin
  Result := WORD(dw);
end;

function HiWord(dw: DWORD): WORD;
begin
  Result := WORD((dw shr 16) and $FFFF);
end;

function WordToHex(w: WORD): string;
begin
  Result := Format('%.4x',[w]);
end;

function FindVolumeSerial(const Drive: string): string;
var
  FileSystemFlags: DWORD;
  VolumeSerialNumber: DWORD;
  MaximumComponentLength: DWORD;
begin
  Result := '';
  // Note on passing PChars using RemObjects Pascal Script:
  // '' pass a nil PChar  
  // #0 pass an empty PChar    
  if GetVolumeInformation(
    PChar(Drive),'',// nil
    0,VolumeSerialNumber,MaximumComponentLength,FileSystemFlags,// nil
    0)
  then
    Result := WordToHex(HiWord(VolumeSerialNumber)) + '-' + WordToHex(LoWord(VolumeSerialNumber));
end;

function InitializeSetup(): Boolean;
begin
  MsgBox(FindVolumeSerial('c:'),mbInformation,mb_Ok);
end;

使用Inno-setup版本5.2.3进行测试在Inno-Setup的Unicode版本中,用PAnsiChar替换PChar

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读