开发者

How to force InnoSetup to create an uninstall log file

开发者 https://www.devze.com 2022-12-24 06:34 出处:网络
I\'m using InnoSetup for creating my application installers and I set the \"SetupLogging=yes\" flag to always create a setup-log file in the %TEMP% directory. This works fine for the installation pro开

I'm using InnoSetup for creating my application installers and I set the "SetupLogging=yes" flag to always create a setup-log file in the %TEMP% directory. This works fine for the installation pro开发者_C百科cedure. Unfortunately, InnoSetup will not create such a log file when I uninstall the application.

Is there a flag / possibility to force InnoSetup to also create an uninstall log file?


I've been able to have the installer write a log file by adding the "/log" option as a parameter to its exe in the Icons section:

[Setup]
...
SetupLogging=yes
...

[Icons]
...
Name: {group}\Uninstall; Filename: {uninstallexe}; Parameters: "/log";


I wrote the following code to implement @mlaan's answer (appending "/log" to the uninstall strings in the registry). Note that I'm only checking HKLM. You could add lines to check HKCU instead or as well.

#define MyAppID "{3D97CC33-75B0-4D86-8533-B213E5FF4046}"

[Setup]
AppId={{#MyAppID}

[Code]
procedure AppendStringToRegValue(const RootKey: integer; const SubKeyName, ValueName, StringToAppend: string);
var
  OldValue: string;  
  NewValue: string;  
  RootKeyString: string;
begin
  case RootKey of
    HKLM: 
      RootKeyString := 'HKLM';
    HKCU: 
      RootKeyString := 'HKCU';
  else 
    RootKeyString := 'RootKey ' + IntToStr(RootKey);
  end;

  if RegQueryStringValue( RootKey, SubKeyName, ValueName, OldValue ) then
  begin
    NewValue := OldValue + StringToAppend
    if RegWriteStringValue( RootKey, SubKeyName, ValueName, NewValue ) then
      Log('Updated ' + RootKeyString + '\' + SubKeyName + '\' + ValueName + '. New Value = [' + NewValue + '].')
    else
      Log('Could not write to ' + RootKeyString + '\' + SubKeyName + '\' + ValueName + '. Value remains [' + OldValue + '].' )
  end
  else
    Log('Could not read from ' + RootKeyString + '\' + SubKeyName + '\' + ValueName + '.' );
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
  OldValue: string;  
  NewValue: string;  
  UninstallSubKeyName:  string;
begin
  if CurStep = ssPostInstall then
  begin
    { Modify uninstall registry entries to add "/log" parameter for uninstall }
    UninstallSubKeyName  := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppID}_is1'
    AppendStringToRegValue(HKLM, UninstallSubKeyName, 'UninstallString', ' /log')
    AppendStringToRegValue(HKLM, UninstallSubKeyName, 'QuietUninstallString', ' /log')
  end;
end;


I am not expert but in my case i noticed that during the install, in the install directory was also created a file with the following name:

 unins000.exe

So, to create the log file for uninstall, i just need to call the file from command line giving the path\name for the log, in my case disinstallazione.log:

unins000.exe  /log="C:\disinstallazione.log"

That's how i could understand what's happening during uninstallation.


P.S. also in my case i have

SetupLogging=yes


No, you would have to use [Code] to update the Uninstall registry key to include a /LOG parameter in the UninstallString value.

The registry key will be either HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall(YourAppID)_is1 or HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall(YourAppID)_is1

Do this at the end on the installation, and only when it succeeded. For example inside an CurStepChanged event function with CurStep = ssPostInstall.


Put these two lines in the [Setup] section of your InnoSetup script

[Setup]
SetupLogging=yes
UninstallLogMode=append

After uninstalling, look in the temp folder for your logs. In Windows7 that location would be

C:\Users\<UserName>\AppData\Local\Temp

You will find a file named something like

Setup Log 2014-12-10 #001.txt

That is your Inno Setup Log file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号