首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Inno安装测试安装程序退出代码

Inno安装测试安装程序退出代码
EN

Stack Overflow用户
提问于 2016-09-28 13:57:43
回答 1查看 1.5K关注 0票数 2

如何访问基于Inno安装程序的返回代码?

例如,文档说,如果“安装程序初始化失败”,退出代码将为1。在我的安装程序中,在某些情况下,代码从False返回InitializeSetup()。我正在使用命令提示符上的/silent标志运行安装程序。如果我echo %errorlevel%,我得到0。

来自InitializeSetup()函数的代码的相关部分:

代码语言:javascript
复制
function InitializeSetup(): Boolean;
var
  ResultCode: Integer;
begin
  // In silent mode, set Result to false so as to exit before wizard is
  // launched in case setup cannot continue.
  if WizardSilent() then
  begin
    // CompareVersion() logically returns the -1, 0 or 1 based on
    // whether the version being installed is less than, equal to or greater
    // than version already installed. Returns 0 is there is no existing
    // installation.
    ResultCode := CompareVersion();
    if ResultCode < 0 then
    begin
      Result := False;
      Exit;
    end;
  end;

  Result := True;
end;

在命令行中,我是如何运行和捕获返回值的:

代码语言:javascript
复制
C:\VersionCheck>myinstaller.exe /Silent

C:\VersionCheck>echo %errorlevel%
0

C:\VersionCheck>

日志文件显示:

代码语言:javascript
复制
2016-09-29 08:05:11.259   Log opened. (Time zone: UTC-07:00)
2016-09-29 08:05:11.259   Setup version: Inno Setup version 5.5.9 (u)
2016-09-29 08:05:11.259   Original Setup EXE: C:\VersionCheck\myinstaller.exe
2016-09-29 08:05:11.259   Setup command line: /SL5="$9051C,3445541,131584,C:\VersionCheck\myinstaller.exe" /Silent
2016-09-29 08:05:11.259   Windows version: 6.3.9600  (NT platform: Yes)
2016-09-29 08:05:11.259   64-bit Windows: Yes
2016-09-29 08:05:11.259   Processor architecture: x64
2016-09-29 08:05:11.259   User privileges: Administrative
2016-09-29 08:05:11.259   64-bit install mode: Yes
2016-09-29 08:05:11.259   Created temporary directory: C:\Users\ADMINI~1\AppData\Local\Temp\2\is-TQB2V.tmp
2016-09-29 08:05:11.275   Installed version component : 3
2016-09-29 08:05:11.275   Updating to version component : 0
2016-09-29 08:05:11.275   This computer already has a more recent version (3.5.0.0) of XYZ. If you wantto downgrade to version 0.0.0.0 then uninstall and try again. Setup will exit.
2016-09-29 08:05:11.275   InitializeSetup returned False; aborting.
2016-09-29 08:05:11.275   Got EAbort exception.
2016-09-29 08:05:11.275   Deinitializing Setup.
2016-09-29 08:05:11.275   Log closed.

我遗漏了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-29 15:21:12

你的测试无效。

当您从命令行执行GUI应用程序(安装程序)时,控制台不会等待程序完成。因此,%errorlevel%不能包含应用程序的退出代码(安装程序),因为它当时还没有完成。

在这种情况下,%errorlevel%只反映启动应用程序的错误(但不是成功的)。

还请注意,静默模式实际上对此没有影响。非静默模式的行为也是一样的。

但是,如果将完全相同的命令添加到批处理文件(.bat)中,它就会工作。当批处理文件等待应用程序完成时。

代码语言:javascript
复制
C:\VersionCheck>test.bat

C:\VersionCheck>myinstaller.exe /Silent

C:\VersionCheck>echo 1
1
C:\VersionCheck>

其中test.bat包含两个命令:

代码语言:javascript
复制
myinstaller.exe /Silent
echo %errorlevel%
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39749701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档