You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Store静默安装需自定义退出码:磁盘空间不足等场景问询

实现Microsoft Store静默安装自定义退出码(基于Inno Setup)

需覆盖的场景及对应标准退出码

  • 应用已存在:1605(MSI标准码,指示操作仅对已安装产品有效)
  • 安装已在进行中:1618(MSI标准码,指示另一个安装进程正在运行)
  • 磁盘空间不足:112(Windows系统错误码,指示磁盘空间不足)

Inno Setup具体实现

1. 检测应用已存在并返回1605

通过检查应用卸载注册表项判断是否已安装,若已存在则设置退出码并终止安装:

function InitializeSetup(): Boolean;
var
  UninstallRegPath: String;
begin
  // 替换为你的应用卸载注册表路径
  UninstallRegPath := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{YourAppUniqueGUID}_is1';
  if RegKeyExists(HKLM, UninstallRegPath) then begin
    ExitCode := 1605;
    Result := False;
  end else begin
    Result := True;
  end;
end;

2. 检测重复安装并返回1618

利用全局互斥体防止并行安装,若检测到已有安装进程则返回对应退出码:

function InitializeSetup(): Boolean;
var
  InstallMutex: THandle;
begin
  // 替换为你的应用唯一互斥体名称
  InstallMutex := CreateMutex(nil, True, 'Global\YourAppInstallMutex');
  if (InstallMutex = 0) or (GetLastError() = ERROR_ALREADY_EXISTS) then begin
    ExitCode := 1618;
    Result := False;
  end else begin
    Result := True;
  end;
end;

3. 磁盘空间不足时返回112

Inno Setup默认磁盘空间不足时返回退出码9,需将其映射为标准码112:

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then begin
    if ExitCode = 9 then begin
      ExitCode := 112;
    end;
  end;
end;

重启需求退出码设置

使用/RESTARTEXITCODE=exit命令行参数指定重启所需退出码,例如:

setup.exe /silent /RESTARTEXITCODE=3010

内容的提问来源于stack exchange,提问作者Tom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 23:35:22