Inno setup 未调用Inno设置函数

Inno setup 未调用Inno设置函数,inno-setup,pascalscript,Inno Setup,Pascalscript,我希望[InstallDelete]部分调用一个自定义函数,该函数将检查是否安装了旧版本(在这种情况下,需要在安装新版本之前删除某些文件) 从我的Inno安装脚本中提取。首先,如果安装了旧版本,则返回True的函数 [Code] function deleteExistingHhd: Boolean; var Version: String; begin MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion

我希望
[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;
不幸的是,生成的设置似乎从未调用自定义函数(当使用此设置安装我的程序时,我从未在自定义函数中找到MsgBox,并且文件未被删除)

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


如有任何帮助/提示,将不胜感激;谢谢

如果您想在安装新软件之前安装它,可以使用以下代码:

#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;
#定义AppName设置设置(“AppName”)
#定义AppVersion设置设置(“AppVersion”)
#定义AppId设置设置(“AppId”)
#如果AppId==“”
#定义AppId AppName
#恩迪夫
[守则]
程序初始化;
变量
卸载,版本:String;
结果代码:整数;
开始
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+''u is1',mbInformation,MB#OK);
如果RegValueExists(HKEY#U LOCAL#U MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+''U is1','DisplayVersion'),然后开始
RegQueryStringValue(HKEY#U LOCAL#U MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+''U is1','DisplayVersion',Version);
MsgBox('现有版本:'+version+'新版本:'+ExpandConstant('{AppVersion}'),mbInformation,MB#OK);
如果是(Version
我想我会保留上面的代码,这可能会对您的问题有所帮助:

#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;
#定义AppName设置设置(“AppName”)
#定义AppVersion设置设置(“AppVersion”)
#定义AppId设置设置(“AppId”)
#如果AppId==“”
#定义AppId AppName
#恩迪夫
[安装删除]
类型:档案;***检查:删除现有HHD;
[守则]
函数deleteExistingHhd:布尔型;
var版本:String;
开始
MsgBox('Checking for key:'+'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+'''u is1',mbInformation,MB#OK);                                                                                                                                                                                                                                               
如果RegValueExists(HKEY#U LOCAL#U MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+''U is1','DisplayVersion'),然后开始
RegQueryStringValue(HKEY#U LOCAL#U MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\'+ExpandConstant('{AppId}')+''U is1','DisplayVersion',Version);
MsgBox('现有版本:'+version+'新版本:'+ExpandConstant('{AppVersion}'),mbInformation,MB#OK);
如果(版本<'1.013'),则开始
结果:=真;
结束结果:=假;
结束结果:=假;
结束;

如果从未调用MsgBox,则会出现其他问题。
我创建了一个新项目,按原样粘贴行,第一个msgbox弹出

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

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

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

而且,您还需要ExpandConstant:),因为否则您将得到前导“{”加倍。它应该在[Setup]部分加倍以转义括号字符。预编译器也将使用#SetupSetting(“AppId”)传递转义前导括号.ExpandConstant实际上不会在此处展开任何常量,但会删除此双括号

以下是完整工作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
#定义MyAppName“我的程序”
#定义MyAppVersion“1.5”
#将MyAppPublisher定义为“我的公司”
#定义MyAppURL“http://www.example.com/"
#定义MyAppExeName“MyProg.exe”
[设置]
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=设置
压缩=lzma
SolidCompression=是
[守则]
函数deleteExistingHhd:布尔型;
var版本:String;
开始
//调试
//{#SetupSetting(“AppId”)}是{#emit SetupSetting(“AppId”)的缩写
Log('注意双括号:{#SetupSetting(“AppId”)});
Log('Now's fine:'+ExpandConstant('{#SetupSetting(“AppId”)}');
日志('这不会展开:'+ExpandConstant('AppId'));
如果RegValueExists(HKEY#U LOCAL_MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting(“AppId”)}U is1'),'DisplayVersion'),则
开始
RegQueryStringValue(HKEY#U LOCAL#U MACHINE,ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#SetupSetting(“AppId”)}#is1'),'DisplayVersion',Version);
MsgBox('现有版本:'+version+'新版本:{#SetupSetting(“AppVersion
#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