Inno Setup安装脚本

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "My Program"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "WpfApp2.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt
#define Uninstall_Name "txt"
[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{0F4C6302-C9BE-4853-A612-EF2094FC51C4}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DefaultGroupName={#MyAppName}
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=C:\Users\Administrator\Desktop\Test
OutputBaseFilename=mysetup
Compression=lzma
SolidCompression=yes
WizardStyle=modern

//import dependency for .net
//isxdl operation
#include "dependency\isxdl.iss"
//;TYPES AND VARIABLES
#include "dependency\products.pas"
//about .net versions
#include "dependency\dotnetfxversion.iss"

//add .net4.5

#include "dependency\.net versions installation\dotnetfx48.iss"

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[CustomMessages]
DependenciesDir=MyProgramDependencies
WindowsServicePack=Windows %1 Service Pack %2
//固定英文安装语言
lcid=1033
depdownload_memo_title=Download dependencies
depinstall_memo_title=Install dependencies
depinstall_title=Installing dependencies
depinstall_description=Please wait while Setup installs dependencies on your computer.
depinstall_status=Installing %1...
depinstall_missing=%1 must be installed before setup can continue. Please install %1 and run Setup again.
depinstall_error=An error occured while installing the dependencies. Please restart the computer and run the setup again or install the following dependencies manually:%n
isxdl_langfile=""

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


IsExist: Boolean;

begin

 

//程序是否运行
Result := IsAppRunning('{#MyAppExeName}') ;
if IsExist then
begin
MsgBox('程序已安装,请先卸载再安装! ', mbError, MB_OK);
result:=false;
end
else if Result then
begin
MsgBox('检测到客户端{#MyAppExeName}正在运行。' #13#13 '请先关闭它然后继续安装! ', mbError, MB_OK);
result:=false;
end

else
begin

dotnetfx48(80); // install if version < 4.6.0
Result := true;
end ;

end ;
// 卸载
function InitializeUninstall(): Boolean;
begin
Result := IsAppRunning('{#MyAppExeName}');
if Result then
begin
MsgBox('检测到客户端{#MyAppExeName}正在运行。' #13#13 '请先关闭它然后继续卸载! ', mbError, MB_OK);
result:=false;
end
else
begin
result := true;
end;
end;


[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "dependency\isxdl.dll"; Flags: dontcopy noencryption
Source: "C:\Users\Administrator\Desktop\WpfApp2\WpfApp2\bin\Debug\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\Users\Administrator\Desktop\WpfApp2\WpfApp2\bin\Debug\Config.txt"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""

 

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{#MyAppName} {#Uninstall_Name}"; Filename: "{uninstallexe}";
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

 参考:https://www.cnblogs.com/kybs0/p/13806494.html

posted @ 2022-07-03 18:29  小痞子Yang  阅读(407)  评论(0编辑  收藏  举报