windows下Inno Setup打包

基于inno setup的windos打包,主要脚本语言inno script。下载地址:https://jrsoftware.org/isdl.php
相关打包教程:https://blog.csdn.net/g710710/article/details/7217424
石材在windows下打包脚本:

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

#define MyAppName "xxxx"
#define MyAppVersion "3.2.4005"                                             
#define MyAppPublisher "xxxx(xxxx IT Group)"
#define MyAppURL "https://www.dq.cn/"
#define MyAppExeName "dqstone.exe"

[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={{C3804F8E-F0DA-4609-9898-437046B06637}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\XXXXITGroup\dqstone
DefaultGroupName={#MyAppName}
; The [Icons] "XXXXX" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.
UsedUserAreasWarning=no
InfoBeforeFile=C:\XXX\xxxx使用协议20210207(SUBOYANG).rtf
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
PrivilegesRequiredOverridesAllowed=dialog
OutputDir=C:\StoneV2
OutputBaseFilename= "{#MyAppName}V({#MyAppVersion})"
SetupIconFile=C:\windows\code.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
//设置控制面板中程序图标
UninstallDisplayIcon=C:\windows\code.ico

//设置控制面板中程序的名称
Uninstallable=yes
UninstallDisplayName={#MyAppName}


[Languages]
Name: "ChineseSimple"; MessagesFile: "compiler:Default.isl"
Name: "English"; MessagesFile: "compiler:Languages\English.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: checkablealone; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode

[Files]
Source: "C:\App\XXX-win32-x64\XXX.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\App\XXX-win32-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon

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

[Code]

// 自定义函数,判断软件是否运行,参数为需要判断的软件的exe名称
function KDetectSoft(strExeName: String): Boolean;
// 变量定义
var ErrorCode: Integer;
var bRes: Boolean;
var strFileContent: AnsiString;
var strTmpPath: String;  // 临时目录
var strTmpFile: String;  // 临时文件,保存查找软件数据结果
var strCmdFind: String;  // 查找软件命令
var strCmdKill: String;  // 终止软件命令
begin
  strTmpPath := GetTempDir();
  strTmpFile := Format('%sfindSoftRes.txt', [strTmpPath]);
  strCmdFind := Format('/c tasklist /nh|find /c /i "%s" > "%s"', [strExeName, strTmpFile]);
  strCmdKill := Format('/c taskkill /f /t /im %s', [strExeName]);
  bRes := ShellExec('open', ExpandConstant('{cmd}'), strCmdFind, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
  if bRes then begin
      bRes := LoadStringFromFile(strTmpFile, strFileContent);
      strFileContent := Trim(strFileContent);
      if bRes then begin
         if StrToInt(strFileContent) > 0 then begin
            if MsgBox(ExpandConstant('卸载程序检测到"{#MyAppName}"正在运行!点击"确定"终止软件后继续操作'), mbConfirmation, MB_OKCANCEL) = IDOK then begin
             // 终止程序
             ShellExec('open', ExpandConstant('{cmd}'), strCmdKill, '', SW_HIDE, ewNoWait, ErrorCode);
             Result:= true;// 继续安装
            end else begin
             Result:= false;// 安装程序退出
             Exit;
            end;
         end else begin
            //MsgBox('软件没在运行', mbInformation, MB_OK);
            Result:= true;
            Exit;
         end;
      end;
  end;
  Result :=true;
end;
// 开始页下一步时判断软件是否运行
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  if 1=CurPageID then begin
      Result := KDetectSoft('XXXX.exe');
      Exit;
  end;
  Result:= true;
end;
  
       
// 卸载时关闭软件
function InitializeUninstall(): Boolean;
begin
  Result := KDetectSoft('XXXXX.exe');
end;

code区代码编写主要用于卸载关闭软件代码编写

// 自定义函数,判断软件是否运行,参数为需要判断的软件的exe名称
function KDetectSoft(strExeName: String): Boolean;
// 变量定义
var ErrorCode: Integer;
var bRes: Boolean;
var strFileContent: AnsiString;
var strTmpPath: String; // 临时目录
var strTmpFile: String; // 临时文件,保存查找软件数据结果
var strCmdFind: String; // 查找软件命令
var strCmdKill: String; // 终止软件命令
begin
strTmpPath := GetTempDir();
strTmpFile := Format('%sfindSoftRes.txt', [strTmpPath]);
strCmdFind := Format('/c tasklist /nh|find /c /i "%s" > "%s"', [strExeName, strTmpFile]);
strCmdKill := Format('/c taskkill /f /t /im %s', [strExeName]);
bRes := ShellExec('open', ExpandConstant('{cmd}'), strCmdFind, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
if bRes then begin
bRes := LoadStringFromFile(strTmpFile, strFileContent);
strFileContent := Trim(strFileContent);
if bRes then begin
if StrToInt(strFileContent) > 0 then begin
if MsgBox(ExpandConstant('卸载程序检测到"{#MyAppName}"正在运行!点击"确定"终止软件后继续操作'), mbConfirmation, MB_OKCANCEL) = IDOK then begin
// 终止程序
ShellExec('open', ExpandConstant('{cmd}'), strCmdKill, '', SW_HIDE, ewNoWait, ErrorCode);
Result:= true;// 继续安装
end else begin
Result:= false;// 安装程序退出
Exit;
end;
end else begin
//MsgBox('软件没在运行', mbInformation, MB_OK);
Result:= true;
Exit;
end;
end;
end;
Result :=true;
end;
// 开始页下一步时判断软件是否运行
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if 1=CurPageID then begin
Result := KDetectSoft('XXX.exe');
Exit;
end;
Result:= true;
end;


// 卸载时关闭软件
function InitializeUninstall(): Boolean;
begin
Result := KDetectSoft('XXXX.exe');
end;

 

posted @ 2021-12-28 19:03  旅途。  阅读(280)  评论(0编辑  收藏  举报