当前位置: 首页 > 知识库问答 >
问题:

未调用 Inno 设置函数

宰鸿博
2023-03-14

我希望< code>[InstallDelete]部分调用一个自定义函数,该函数将检查是否安装了旧版本(在这种情况下,某些文件需要在安装新版本之前删除)。

从我的Inno安装脚本中提取。首先,如果安装了旧版本,该函数返回True。

[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
  MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', mbInformation, MB_OK);

  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion') then
    begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('AppId')+'_is1', 'DisplayVersion', Version);
      MsgBox('Existing version:'+Version+'  New version:'+ExpandConstant('AppVersion'), mbInformation, MB_OK);
      if (Version < '1.013') then
        begin
          Result := True;
        end
      else
        begin
          Result := False;
        end
    end
  else
    begin
      Result := False;
    end
end;

然后是应该调用这个函数的部分:

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;

不幸的是,生成的设置似乎从来没有调用自定义函数(当用这个设置安装我的程序时,我从来没有得到位于自定义函数中的MsgBox,文件也没有被删除)。

Inno Setup编译时,我的函数是否有一些错误没有显示出来?如果是,我在哪里可以找到它们?

非常感谢任何帮助/提示;谢谢

共有2个答案

印子平
2023-03-14

如果你想在安装它之前用新的它来取消它,你可以使用以下代码:

#define AppName  SetupSetting('AppName')     
#define AppVersion  SetupSetting('AppVersion')
#define AppId  SetupSetting('AppId')             
#if AppId == ""   
  #define AppId AppName
#endif 

[Code]
procedure InitializeWizard;
var
  Uninstall,Version: String;
  ResultCode:Integer;
begin
  MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);
  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', 'DisplayVersion') then begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', 'DisplayVersion', Version);
      MsgBox('Existing version:'+Version+'  New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
      if (Version < ExpandConstant('{#AppVersion}')) then begin               
          RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1','UninstallString', Uninstall);
          Exec(RemoveQuotes(Uninstall), ' /RECAll /SILENT' , '', SW_SHOW, ewWaitUntilTerminated, ResultCode);   
        end
    end
end;

我想我会保留上面的代码,对于您的问题,这可能会有所帮助:

#define AppName  SetupSetting('AppName')     
#define AppVersion  SetupSetting('AppVersion')
#define AppId  SetupSetting('AppId')             
#if AppId == ""   
  #define AppId AppName
#endif 

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check:deleteExistingHhd;

[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin
  MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', mbInformation, MB_OK);                                                                                                                                                                                                                                               
  if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', 'DisplayVersion') then begin
    RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{#AppId}')+'_is1', 'DisplayVersion', Version);
    MsgBox('Existing version:'+Version+'  New version:'+ExpandConstant('{#AppVersion}'), mbInformation, MB_OK);
    if (Version < '1.013') then begin
        Result := True;
    end else Result := False;
  end else Result := False;
end;
庄智
2023-03-14

如果从未调用MsgBox,则存在其他问题
我创建了一个新项目,按原样粘贴您的行,然后弹出第一个消息框。

也许只是开始一个新的,并继续从旧的设置脚本中添加部分,直到找到阻止函数执行的原因。

您知道可以使用F7和/或断点F5单步执行代码吗?这应该可以帮助您找到问题,它应该是:[InstallDelete]-

@IZB是正确的,ExpandConstant('AppId')将被解析为AppId,而不是实际ID。 检查调试部分的输出 我在下面添加了您的脚本。观看Inno Seput编译器底部的“调试输出”,同时逐步执行代码。

AND,您还需要扩展常量:),因为否则您将获得前导“{”的两倍。它应该在[Setup]部分中加倍以转义括号字符。预编译器也将使用#SetupSVD(“AppId”)传递转义前导括号。扩展常量实际上不会在这里扩展任何常量,但会删除这个加倍的小括号。

以下是完整工作iss文件的粘贴:

#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "http://www.example.com/"
#define MyAppExeName "MyProg.exe"

[Setup]
AppId={{CB77C990-DECF-4697-B377-8F76799CC6B7}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup
Compression=lzma
SolidCompression=yes

[Code]
function deleteExistingHhd: Boolean;
var Version: String;
begin

  // Debugging
  // {#SetupSetting("AppId")} is short from {#emit SetupSetting("AppId")}
  Log('Note the double bracket: {#SetupSetting("AppId")}');
  Log('Now it''s fine: ' + ExpandConstant('{# SetupSetting("AppId")}'));
  Log(' This won''t expand: ' + ExpandConstant('AppId'));

  if RegValueExists(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion') then
    begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting("AppId")}_is1'), 'DisplayVersion', Version);
      MsgBox('Existing version:' + Version + '  New version:{#SetupSetting("AppVersion")}', mbInformation, MB_OK);
      if (Version < '1.013') then Result := True
      else Result := False;
    end
  else Result := False;
end;

[InstallDelete]
Type: files; Name: {userappdata}\xxx\*.hhd; Check: deleteExistingHhd
 类似资料:
  • 我正在尝试构建一个带有Inno Setup的安装程序,该安装程序基于一些配置选项运行其他安装程序。为了简单起见,假设我有20个安装程序,可以在5种不同的配置中设置,其中每个配置都有一些必需的和一些可选的安装程序。配置A可能需要安装程序1、2、5、6,并有11、13和14的选项。配置B可能需要1、2、3、9,并有12、19和20的选项。以此类推。 我为每个安装程序准备了一个组件。理想情况下,我想使用

  • 在中设置回调函数时,要使用什么? 我尝试将函数设置为类型<code>void。将其更改为<code>void __stdcall,但如何使用<code>GLFW的<code>typedef,例如<code>GLFW*fun?我认为这是正确的选择。我真的需要一个示例源代码。 顺便说一句,我将GLFW定义为 更新 我的代码是这样的: (我以三种方式做到了) 一 原型。因为在下面,所以这个给我一个编译错

  • 这是我在INNO设置中的三个示例部分。我想在INI部分使用。我该怎么做?

  • 如果软件已经安装了旧版本,我需要Inno Setup生成的安装程序在安装之前删除某些文件。 我试图通过比较版本号(下面的自定义函数)来做到这一点,但是在编译时,Inno Setup生成了一个错误: [ISPP]未声明的标识符:“获取安装版本”。 Inno安装脚本相关摘录如下: 作为Inno Setup的新手,这当然是一个微不足道的问题,但在论坛上找不到答案。因此,问题是:如何从部分正确调用函数?

  • 我使用的是react native而不是expo,当尝试使用UseState设置值时,它不会立即设置,并且我无法获取值​​在另一个功能中。 如何让它等待设置,然后调用函数pressed()

  • 问题内容: 为什么下面的代码不打印任何内容: 我正在Python 3中执行上述代码。我想我缺少了一些非常基本的东西,但无法弄清楚。 问题答案: 返回iterator,直到您要求它之前,它不会处理元素。 将其变成列表以强制处理所有元素: 或将其长度设置为0以不产生列表(如果不需要地图输出): 但是请注意,对于任何以后的代码维护者而言,简单地使用循环都更具可读性: