Inno Setup function not called

匿名 (未验证) 提交于 2019-12-03 01:26:01

问题:

I would like the [InstallDelete] section to call a custom function that will check if an older version is installed (in which case certain files need to be deleted prior installation of the new version).

Extract from my Inno Setup script. First the function that returns True if an older version is installed.

[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;

Then the section that should call this function:

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

Unfortunately the generated setup seems to never call the custom function (when installing my program with this setup I never get the MsgBox located in the custom function and the files are not deleted).

Is it possible that my function has some errors that are not indicated when Inno Setup compiles? If so, where could I find them?

Any help / hint would be very much appreciated; thanks!

回答1:

If the MsgBox is never called, there is something else wrong.
I created a new project, pasted your lines as-is and the first msgbox pops-up.

Maybe just start a new, and keep adding parts from your old setup script until you'll find what is stopping the function from executing.

Did you know you can step through the code using F7 and/or breakpoints F5? That should help you locate the problem, It should go: [InstallDelete] -> [Dirs] -> [Files]

@IZB is right, ExpandConstant('AppId') will be resolved as AppId and not the actual ID. Check the output from the debugging section I added the your script below. Watch the "Debug output" on bottom of Inno Seput Compiler while stepping through the code.

AND, You also need the ExpandConstant :) because otherwise you'll get the leading '{' doubled. It should be doubled in [Setup] section to escape the bracket character. The pre-compiler will pass the escape leading bracket too, using #SetupSetting("AppId") . ExpandConstant will not actually Expand any constant here, but will remove this doubled bractet.

Here is paste of complete working iss file:

#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


回答2:

If you want to unistall it before install it with new one you can use this code:

#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;

I think I'll keep code above and for you problem may this will help:

#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;


转载请标明出处:Inno Setup function not called
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!