在进行 WPF 程序打包发布的时候如果对程序打包没有特别高的要求,InnoSetup 足以胜任普通的程序打包发布需求,它支持安装包加密,安装包升级安装,注册表操作等常规功能,以下脚本示例中有对常见操作进行相关说明。


简介

示例脚本

; 脚本由 Inno Setup 脚本向导 生成!
; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! ; 程序名称
#define MyAppName "hippieZhou"
; 程序版本号
#define MyAppVersion "2.2.0.5"
; 发布商名称
#define MyAppPublisher "hippieZhou, Inc."
; 发布商网址
#define MyAppURL "http://www.cnblogs.com/hippieZhou"
; 执行主程序名称
#define MyAppExeName "hippieZhou.exe"
[Setup]
; 注: AppId的值为单独标识该应用程序。
; 不要为其他安装程序使用相同的AppId值。
; (生成新的GUID,点击 工具|在IDE中生成GUID。)
AppId={{5597878A-538D-4164-B06A-2DC56C9ED8EE}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\TerraVision
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
; 程序打包输出目录
OutputDir=Build\
OutputBaseFilename=setup
SetupIconFile=Application.ico
Compression=lzma
SolidCompression=yes
VersionInfoVersion={#MyAppVersion}
ArchitecturesAllowed=x64
; 以64位架构模式进行安装
ArchitecturesInstallIn64BitMode=x64
; 以管理员模式运行
PrivilegesRequired=poweruser
; 安装程序安装密码
Password=123456
; 是否加密
Encryption=yes
[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
; 指定主程序
Source: "Src\TerraVision.Shell.exe"; DestDir: "{app}"; Flags: ignoreversion
; 拷贝程序文件到指定目录
Source: "Src\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”
; 检测当前程序是否在运行
[Code]
function IsAppRunning(const FileName : string): Boolean;
var
FSWbemLocator: Variant;
FWMIService : Variant;
FWbemObjectSet: Variant;
begin
Result := false;
FSWbemLocator := CreateOleObject('WBEMScripting.SWBEMLocator');
FWMIService := FSWbemLocator.ConnectServer('', 'root\CIMV2', '', '');
FWbemObjectSet := FWMIService.ExecQuery(Format('SELECT Name FROM Win32_Process Where Name="%s"',[FileName]));
Result := (FWbemObjectSet.Count > 0);
FWbemObjectSet := Unassigned;
FWMIService := Unassigned;
FSWbemLocator := Unassigned;
end;
function InitializeSetup(): Boolean;
begin
if IsAppRunning('hippiezhou.exe') then
begin
if MsgBox('程序正在运行,请先关闭后再进行安装!',mbInformation,MB_OK) = idYes then
begin
Result := False;
end
end
else
begin
Result := True;
end
end;
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

相关参考

05-11 21:55