Outils pour utilisateurs

Outils du site


prog:inno_setup

Site Web, Archive v6.2.0

Modifier un fichier après installation

Utilité : modifier un pattern pour le remplacer, par exemple, par le dossier final d'installation.

Ajouter après chaque fichier une directive AfterInstall.

Source: "C:\fichier.txt"; DestDir: "{app}"; Flags: ignoreversion; AfterInstall: FileReplaceString('fichier.txt')

Puis, dans une section [Code] (à créer si inexistante) :

procedure FileReplaceString(const FileName: string);
va
  MyFile : TStrings;
  MyText : string;
begin
  MyFile := TStringList.Create;
 
  try
    MyFile.LoadFromFile(ExpandConstant('{app}') + '\' + FileName);
    MyText := MyFile.Text;
 
    StringChangeEx(MyText, 'C:\BlaBla\', ExpandConstant('{app}') + '\', True);
 
    MyFile.Text := MyText;
    MyFile.SaveToFile(ExpandConstant('{app}') + '\' + FileName);
  finally
    MyFile.Free;
  end;
end;

Modification de la base de registre

Ici, pour lancer le programme en mode administrateur.

[Registry]
; Pour forcer l'exécution en mode administrateur
Root: HKLM; Subkey: "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; ValueType: string; ValueName: "{app}\prog.exe"; ValueData: "RUNASADMIN"

Création d'un raccourci

shortcut.pas, Archive

const
  CLSID_ShellLink = '{00021401-0000-0000-C000-000000000046}';
 
type
  IShellLinkW = interface(IUnknown)
    '{000214F9-0000-0000-C000-000000000046}'
    procedure Dummy;
    procedure Dummy2;
    procedure Dummy3;
    function GetDescription(pszName: String; cchMaxName: Integer): HResult;
    function SetDescription(pszName: String): HResult;
    function GetWorkingDirectory(pszDir: String; cchMaxPath: Integer): HResult;
    function SetWorkingDirectory(pszDir: String): HResult;
    function GetArguments(pszArgs: String; cchMaxPath: Integer): HResult;
    function SetArguments(pszArgs: String): HResult;
    function GetHotkey(var pwHotkey: Word): HResult;
    function SetHotkey(wHotkey: Word): HResult;
    function GetShowCmd(out piShowCmd: Integer): HResult;
    function SetShowCmd(iShowCmd: Integer): HResult;
    function GetIconLocation(pszIconPath: String; cchIconPath: Integer;
      out piIcon: Integer): HResult;
    function SetIconLocation(pszIconPath: String; iIcon: Integer): HResult;
    function SetRelativePath(pszPathRel: String; dwReserved: DWORD): HResult;
    function Resolve(Wnd: HWND; fFlags: DWORD): HResult;
    function SetPath(pszFile: String): HResult;
  end;
 
  IPersist = interface(IUnknown)
    '{0000010C-0000-0000-C000-000000000046}'
    function GetClassID(var classID: TGUID): HResult;
  end;
 
  IPersistFile = interface(IPersist)
    '{0000010B-0000-0000-C000-000000000046}'
    function IsDirty: HResult;
    function Load(pszFileName: String; dwMode: Longint): HResult;
    function Save(pszFileName: String; fRemember: BOOL): HResult;
    function SaveCompleted(pszFileName: String): HResult;
    function GetCurFile(out pszFileName: String): HResult;
  end;
 
procedure CreateShortCut(const FileName: string; const argument: string; const destination: string);
var
  Obj: IUnknown;
  SL: IShellLinkW;
  PF: IPersistFile;
begin
  if IsTaskSelected('shortcutstart') then
  begin
    { Create the main ShellLink COM Automation object }
    Obj := CreateComObject(StringToGuid(CLSID_ShellLink));
 
    { Set the shortcut properties }
    SL := IShellLinkW(Obj);
    OleCheck(SL.SetPath(ExpandConstant('{app}') + '\' + FileName));
    OleCheck(SL.SetArguments(argument));
    OleCheck(SL.SetShowCmd(SW_SHOWNORMAL));
 
    { Save the shortcut }
    PF := IPersistFile(Obj);
    OleCheck(PF.Save(ExpandConstant('{commonstartup}') + '\' + destination + '.lnk', True));
  end;
end;

Exemple d'utilisation :

AfterInstall: CreateShortCut('runner.exe', ExpandConstant('{app}\file.exe'), 'Raccourci')
prog/inno_setup.txt · Dernière modification : 2022/02/11 21:56 de root