程序打包

本文介绍了使用Inno Setup和NSIS进行程序打包的全过程,包括修改文件、检查运行库、设置软件运行、背景图、数字签名等。详细讲解了各个工具的使用,如WixToolSet、Advanced Installer,并提到了界面美化和安装包属性的设置,还涵盖了安装包的条件、功能、卸载文件的管理以及用户接口的定制。同时,文章还涉及了Enigma Virtual Box等软件虚拟化工具。
摘要由CSDN通过智能技术生成
Source: "C:\Example\原始文件\log\*"; DestDir: "{app}\log"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion”
;安装类型设置
[Types]
Name: Full ;Description:"完全安装"; Flags: iscustom
Name: Compact ;Description:"简洁安装";
Name: Custom; Description:"自定义安装";
;组件安装
[Components]
Name: c1; Description: "自定义任务3" ; Types: Full
Name: a1; Description: "安装Components_1"; Types: Full Compact Custom ;
Name: a2; Description: "安装Components_2"; Types : Full   Compact
Name: a3; Description: "安装Components_3"; Types : Full
 
;开始菜单,桌面快捷方式
[Icons]
Name: "{group}\ISsample"; Filename: "{app}\ISsample.exe"
Name: "{group}\{cm:ProgramOnTheWeb,ISsample}"; Filename: "http://zwkufo.blog.163.com"
Name: "{group}\{cm:UninstallProgram,ISsample}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\ISsample"; Filename: "{app}\ISsample.exe"; Tasks: quicklaunchicon
;添加一个帮助文挡
Name: {group}\ISsample 1.0.0.0 帮助文档;Filename: {app}\ISsample.chm
 
;用来在程序安装完成后 在安装程序显示最终对话框之前执行程序 常用与运行主程序 显示自述文件 删除临时文件
[Run]
Filename: "{app}\ISsample.exe"; Description: "{cm:LaunchProgram,ISsample}"; Flags: nowait postinstall skipifsilent
Filename: "{app}\ISsample.txt"; Description: "查看显示自述文件"; Flags: postinstall skipifsilent shellexec
 
;更改显示在程序中显示的消息文本
[Messages]
BeveledLabel=HKiss科技
;卸载对话框说明
ConfirmUninstall=您真的想要从电脑中卸载ISsample吗?%n%n按 [是] 则完全删除 %1 以及它的所有组件;%n按 [否]则让软件继续留在您的电脑上.
;定义解压说明
;StatusExtractFiles=解压并复制主程序文件及相关库文件...
 
;用于在用户系统中创建,修改或删除ini文件健值
[INI]
Filename: "{app}\cfg.ini"; Section: "Startup Options"; Flags: uninsdeletesection
Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server ip"; String: "127.0.0.1"
Filename: "{app}\cfg.ini"; Section: "Startup Options"; Key: "server port"; String: "8080"
 
;用于在用户系统中创建,修改或删除注册表健值
[Registry]
Root: HKLM ;SubKey:"Software\ISsample";ValueType:dword;ValueName:config;ValueData:10 ;Flags:uninsdeletevalue
;在执行脚本
[code]
//全局变量
var MyProgChecked: Boolean;
 
//判断程序是否存在
//初始华程序事件
function InitializeSetup(): boolean;
var Isbl: boolean;         //声明变量
var Isstr: string;
begin       //开始
Isbl := true;             //变量赋值
Isstr := '欢迎';
if RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\ISsample', 'config') then
begin
    MsgBox('已安装过,请先卸载在安装',mbConfirmation, MB_OK);
    isbl := false;
end else
begin
   //MsgBox('无值',mbConfirmation, MB_OK);
     isbl := true;
end;
 
//下面是个麻烦的 条件语句 end else 注意
//if MsgBox(Isstr, mbConfirmation, MB_OKCANCEL) = IDOK then
//begin
// isbl := true;
// MsgBox('执行了', mbConfirmation, MB_OK);
//end else
//begin
// isbl := false;
//MsgBox('执行了', mbConfirmation, MB_OK);
//end;
 
Result := Isbl;
end;       //结束
 
procedure CurStepChanged(CurStep: TSetupStep);
var Isstr :string;
begin
if CurStep=ssInstall then       //实际安装前调用
begin
    //MsgBox('CurStepChanged:实际安装前调用', mbConfirmation, MB_OKCANCEL);           //安装完成后调用
end;
if CurStep=ssPostInstall then
begin
    Isstr := ExpandConstant('{tmp}\tmp.rar');
//    if FileExists(Isstr) then
//    begin
//      MsgBox('文件存在',mbConfirmation, MB_OK);
//    end else
//    begin
//      MsgBox('文件不存在',mbConfirmation, MB_OK);
//    end;
   // MsgBox('CurStepChanged:实际安装后调用', mbConfirmation, MB_OKCANCEL);
end;
end;
 
//下一步 按钮按钮 事件
function NextButtonClick(CurPageID: Integer): Boolean;
var ResultCode: Integer;
var IsSetup : Boolean;
begin
IsSetup := true ;
case CurPageID of
    wpSelectDir:
       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardDirValue + '''.', mbInformation, MB_OK);   //WizardDirValue路径
    wpSelectProgramGroup:
       MsgBox('NextButtonClick:' #13#13 'You selected: ''' + WizardGroupValue + '''.', mbInformation, MB_OK); //开始菜单名
    wpReady:
      begin
       if not RegValueExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Test', 'config') then   begin
          if MsgBox('程序执行需要Test.ext,是否安装!', mbConfirmation, MB_YESNO) = idYes then begin
           ExtractTemporaryFile('test.exe');
            if not Exec(ExpandConstant('{tmp}\test.exe'), '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode) then
              MsgBox('Test.exe出错:' #13#13 ' ' + SysErrorMessage(ResultCode) + '.', mbError, MB_OK);
          end else begin
                IsSetup := false ;
          end ;
          BringToFrontAndRestore();
        end;
      end;
end;
Result := IsSetup;
end;

修改文件某行

procedure test2();
var
  fileName,tempStr:String;
  svArray: TArrayOfString;
  nLines,i:Integer; 
begin 
  fileName := ExpandConstant('{app}\Apache\conf\httpd.conf');
  LoadStringsFromFile(fileName, svArray);
  nLines := GetArrayLength(svArray); 
  for i := 0 to nLines - 1 do
  begin
    tempStr := svArray[i];
    if (1 = Pos('ServerRoot', tempStr)) then    //Pos函数,判断当前行是否含有'ServerRoot'子串,返回1表示在1的位置找到子串,若不能找到该子串返回0
    begin
      svArray[i] := ExpandConstant('ServerRoot "{app}\Apache\"');  //修改开头是'ServerRoot'那行文本,此时只是修改内存数据的内容,并未写入文件
      StringChangeEx(svArray[i], '\', '/', True);      //StringChangeEx函数,将字符串中所有的符号\替换为符号/
    end;
    if (1 = Pos('Listen', tempStr)) then         //找到端口配置行
      svArray[i] := 'Listen 80';            //修改Apache端口号
    if (1 = Pos('DocumentRoot', tempStr)) then
    begin 
      svArray[i] := ExpandConstant('DocumentRoot "{app}\Apache\htdocs"');
      StringChangeEx(svArray[i], '\', '/', True);
    end;
    if ((1 = Pos('<Directory', tempStr)) and (Pos('htdocs', tempStr) > 1)) then
    begin
      svArray[i] := ExpandConstant('<Directory "{app}\Apache\htdocs">');
      StringChangeEx(svArray[i], '\', '/', True);
    end;
  end;
  SaveStringsToFile(fileName, svArray, false);    //最后从内存写回原文件,false表示不追加直接覆盖之前所有内容
end;

查看是否安装运行库

var
	vcSP1Missing: Boolean;
function NeedInstallVCSP1(): Boolean;
begin
 Result := vcSP1Missing;
end;

function InitializeSetup(): Boolean;
begin
 vcSP1Missing := true;
 if RegKeyExists(HKLM, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{710f4c1c-cc18-4c49-8cbf-51240c89a1a2}')
 then
   begin
     vcSP1Missing := false;
   end;
 result := true;
end;

软件是否运行

function IsAppRunning(const FileName : string): Boolean;
var 
ProcessRunState :Integer;
begin
    result := false;
    Exec('cmd.exe', Format('/C tasklist|findstr /i %s',[FileName]), '', SW_HIDE,ewWaitUntilTerminated, ProcessRunState); 
    if (ProcessRunState = 0) then
    begin
        result := true;
    end;
end;

修改背景图

WizardImageFile=myimage.bmp,myimage2.bmp

100%	164x314
125%	192x386
150%	246x459
175%	273x556
200%	328x604
225%	355x700
250%	410x797

WizardSmallImageFile=mysmallimage.bmp,mysmallimage2.bmp

100%	55x55
125%	64x68
150%	83x80
175%	92x97
200%	110x106
225%	119x123
250%	138x140

数字签名

https://jingyan.baidu.com/article/11c17a2c065713f446e39dc1.html

http://cicada.bajiaohuixiang.com/article/snapshot?id=92&type=clean

其他文档

Inno Setup 常量与Windows环境变量的对应

RemObjects Pascal脚本

Pascal Scripting: Support Functions Reference

Inno Setup脚本语法大全

使用Inno Setup函数修改文件内容

模块化InnoSetup依赖安装程序

判断已安装运行库版本

MsiQueryProductState

免费pascal

InnoSetup打包 添加.NET环境安装

inno setup读取注册表遇到的一个坑

64位操作系统读取注册表问题:

function GetInstallString(): String;
var
  sInstallPath: String;
begin
  sInstallPath := 'C:\Program Files\Adobe\Common\Plug-ins\7.0\MediaCore';
  if RegValueExists(HKLM64, 'SOFTWARE\Adobe\Premiere Pro\CurrentVersion', 'Plug-InsDir') then
  begin
    RegQueryStringValue(HKLM64, 'SOFTWARE\Adobe\Premiere Pro\CurrentVersion', 'Plug-InsDir', sInstallPath)
  end
  Result := sInstallPath;
end;

NSIS 设置安装包exe属性中的详细信息

我们首先将安装界面的语言设置为简体中文 SimpChinese

; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
 
VIProductVersion "${PRODUCT_VERSION}" ;版本号,格式为 X.X.X.X (若使用则本条必须)
VIAddVersionKey  /LANG=${LANG_SimpChinese} "ProductName" "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赤龙绕月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值