请参考以下脚本(我也是参考 Inno Setup 帮助现学的):
[Setup]
AppName=My Program
AppVersion=1.5
;从代码中获取原程序的安装目录,好处是如果获取的目录为空,可以定义一个默认的
DefaultDirName={code:MyConst}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
Compression=lzma2
SolidCompression=yes
OutputDir=userdocs:Inno Setup Examples Output
; "ArchitecturesAllowed=x64" specifies that Setup cannot run on
; anything but x64.
ArchitecturesAllowed=x64
; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64
[Files]
Source: "MyProg-x64.exe"; DestDir: "{app}"; DestName: "MyProg.exe"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
[Code]
Function MyConst(Path: String): String;
begin
Result := ExpandConstant('{pf}'); //预定义一个安装根目录
RegQueryStringValue(HKLM,'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Microsoft Security Client','InstallLocation',Path);
if Path <> '' then
Result := ExtractFileDrive(Path); //提取根目录
end;