Inno Setup的常用脚本
Inno Setup的常用脚本
Source: "我的程序\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "我的程序\*"; DestDir: {cf}\我的程序; Flags: ignoreversion recursesubdirs createallsubdirs
[Icons]
Name: "{group}\我的程序名称"; Filename: "{app}\我的程序.exe" ;WorkingDir: "{app}"
桌面快捷方式:
[Icons]
Name: "{userdesktop}\我的程序名称"; Filename: "{app}\我的程序.exe"; WorkingDir: "{app}"
开始菜单卸载快捷方式:
[Icons]
Name: "{group}\{cm:UninstallProgram,我的程序}"; Filename: "{uninstallexe}"
安装完后选择运行:
[Run]
Filename: "{app}\我的程序.exe"; Description: "{cm:LaunchProgram,我的程序名称}"; Flags: nowait postinstall skipifsilent
安装完后自动运行:
[Run]
Filename: "{app}\我的程序.exe";
在界面左下角加文字:
[Messages]
BeveledLabel=你的网站名称
选择组件安装:(组件1的Flags: fixed为必须安装)
[Types]
Name: "full"; Description: "选择安装"; Flags: iscustom
[Components]
Name: 组件1文件夹; Description: 组件1名称; Types: full; Flags: fixed
Name: 组件2文件夹; Description: 组件2名称; Types: full
Name: 组件3文件夹; Description: 组件3名称; Types: full
[Files]
Source: "E:\组件1文件夹\我的程序.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "E:\组件1文件夹\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: 组件1文件夹
Source: "E:\组件2文件夹\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: 组件2文件夹
Source: "E:\组件3文件夹\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: 组件3文件夹
添加关于按钮:
[Code]
{注意:关于按钮单击后执行的过程,一定要写在InitializeWizard()过程之前}
procedure ButtonAboutOnClick(Sender: TObject);
begin
MsgBox('关于对话框。'+#13#10+'另起一行', mbInformation, MB_OK);//显示对话框
end;
{初始化安装向导时会触发的过程,这个过程的名字是INNO内部定义的,不能修改}
procedure InitializeWizard();
begin
with TButton.Create(WizardForm) do//在WizardForm上面创建一个按钮
begin
Left := 32;//按钮距WizardForm左边的距离
Top := 302;//按钮距WizardForm上边的距离
Width := WizardForm.CancelButton.Width;//按钮的宽度,这里定义跟'取消'按钮等宽
Height := WizardForm.CancelButton.Height;//按钮的高度
Caption := '关于(&A)...';//按钮上的文字
Font.Name:='宋体';//按钮文字的字体
Font.Size:=9;//9号字体
OnClick := @ButtonAboutOnClick;//单击按钮触发的过程,就是前面的'ButtonAboutOnClick'过程,注意前面不要漏掉
Parent := WizardForm;//按钮的父组件,也就是按钮'载体',这里是WizardForm(安装向导窗体)
end;
end;
设置界面文字颜色:
[Code]
procedure InitializeWizard();
begin
WizardForm.WELCOMELABEL1.Font.Color:= clGreen;//设置开始安装页面第一段文字的颜色为绿色
WizardForm.WELCOMELABEL2.Font.Color:= clOlive;//设置开始安装页面第二段文字的颜色为橄榄绿
WizardForm.PAGENAMELABEL.Font.Color:= clred;//设置许可协议页面第一段文字的颜色为红色
WizardForm.PAGEDESCRIPTIONLABEL.Font.Color:= clBlue; //设置许可协议页面第二段文字的颜色为蓝色
WizardForm.MainPanel.Color:= clWhite;//设置窗格的颜色为白色
end;
判断所选安装目录中原版主程序是否存在:
function NextButtonClick(CurPage: Integer): Boolean;
begin
Result:= true;
if CurPage=wpSelectDir then
if not FileExists(ExpandConstant('{app}\主程序.exe')) then
begin
MsgBox('安装目录不正确!', mbInformation, MB_OK );
Result := false;
end;
end;
颜色:
clBlack(黑色),clMaroon(暗红),clGreen(绿色),clOlive(橄榄绿),clNavy(深蓝),clPurple(紫
色),clTeal(深青),clGray(灰色),clSilver(浅灰),clRed(红色),clLime(浅绿),clYellow(黄
色),clBlue(蓝色),clFuchsia(紫红),clAqua(青绿),clWhite(白色)。te(白色)。
Root: HKLM; Subkey:
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment"; ValueType: string; ValueName: "Path"; ValueData:
"{olddata};{app}";Flags:uninsdeletekey
0、调用DOS命令或批处理等其它命令行工具等
Exec(ExpandConstant('{cmd}'), '/c dir c:\ >a.txt',ExpandConstant('{app}'), SW_SHOWNORMAL, ewNoWait, ResultCode);
1、不显示一些特定的安装界面
[code]
function ShouldSkipPage(PageID: Integer): Boolean;
begin
if PageID=wpReady then
result := true;
end;
wpReady 是准备安装界面
PageID查询 INNO帮助中的 Pascal 脚本: 事件函数常量
预定义向导页 CurPageID 值
wpWelcome, wpLicense, wpPassword, wpInfoBefore, wpUserInfo, wpSelectDir,
wpSelectComponents, wpSelectProgramGroup, wpSelectTasks, wpReady,
wpPreparing, wpInstalling, wpInfoAfter, wpFinished
如果是自定义的窗体,则PageID可能是100,你可以在curPageChanged(CurPageID: Integer)方法中打印出到curpageid到底是多少。
2、获取SQLserver安装路径
var
dbpath:string;
rtn:boolean;
rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\MSSQLServer\Setup','SQLPath', dbpath);
if (!rtn) then dbpath := ExpandConstant('{app}');
3、获取本机的IP地址
ip:string;
rtn:boolean;
//{083565F8-18F0-4F92-8797-9AD701FCF1BF}视网卡而定见LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards处
rtn :=RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Services\{083565F8-18F0-4F92-8797-9AD701FCF1BF}\Parameters\TcpIp','IpAddress',
ip);
if (not rtn) or (ip='0.0.0.0') or (ip='') then ip := '127.0.0.1';
4、检查数据库是否安装
//检查是否已安装SQL
try
CreateOleObject('SQLDMO.SQLServer');
except
RaiseException('您还没有安装SQL数据库.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
end;
5、根据环境变量选择组件,获取系统环境变量值见方法6
procedure CurPageChanged(CurPageID: Integer);
var
path:string;
rtn:boolean;
begin
//MsgBox(inttostr(curpageid),mbInformation,mb_ok);
if (curpageId =7) then
begin
rtn := checkTomcat6(path);
if rtn then//如果系统以前没安装tomcat则选中组件,否则不选中
begin
WizardForm.ComponentsList.CheckItem(2,coUnCheck);
WizardForm.ComponentsList.ItemEnabled[2] := false;
end;
end;
end;
6、系统环境变量操作
读取:
function GetEnv(const EnvVar: String): String;
举例:GetEnv('java_home')
设置:
[Setup]
ChangesEnvironment=true
[code]
//环境变量名、值、是否安装(删除)、是否所有用户有效
procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall: Boolean);//设置环境变量函数
var
sOrgValue: string;
x,len: integer;
begin
//得到以前的值
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)
sOrgValue := Trim(sOrgValue);
begin
x := pos( Uppercase(aEnvValue),Uppercase(sOrgValue));
len := length(aEnvValue);
if aIsInstall then//是安装还是反安装
begin
if length(sOrgValue)>0 then aEnvValue := ';'+ aEnvValue;
if x = 0 then Insert(aEnvValue,sOrgValue,length(sOrgValue) +1);
end
else
begin
if x>0 then Delete(sOrgValue,x,len);
if length(sOrgValue)=0 then
begin
RegDeleteValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',aEnvName);
exit;
end;
end;
StringChange(sOrgValue,';;',';');
RegWriteStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
aEnvName, sOrgValue)
end;
end;
7、获取NT服务安装路径
Windows服务在系统安装后会在注册表的 "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"下
以服务的ServiceName建1个目录,
目录中会有"ImagePath"
举例获取tomcat6服务安装路径:
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\tomcat6','ImagePath', sPath);
------------------------------------------------------------------------
算不上原创,可也花费了很多时间心血查资料、整理、调试
Inno Setup的常用脚本的更多相关文章
- inno setup教程解释脚本
inno setup教程解释脚本 2007-04-08 21:31:36| 分类: 科技-> Inno Setu | 标签:inno |举报 |字号 订阅 下载LOFTER客户端 ...
- [InnoSetup]Inno Setup软件打包脚本
脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "SFT期货交易系统&quo ...
- 【Inno Setup】Pascal 脚本 ---- 事件函数
转载 事件函数 Inno Setup支持以下函数和过程. 1. [安装初始化]该函数在安装程序初始化时调用,返回False 将中断安装,True则继续安装,测试代码如下: function Initi ...
- 分享一个自用的 Inno Setup 软件打包脚本
此脚本支持打包mysql.安装mysql服务.安装windows服务.操作ini文件.操作注册表.高效压缩文件等功能,基本能满足常用的软件打包需求. ;定义各种常量 #define MyAppName ...
- Inno Setup执行SQL脚本的方法
作为和NSIS并立的.两个最流行的免费Windows应用程序安装包制作工具之一,Inno在学习难度上相对要低一些,非常适合对一些简单的桌面程序打包.但对于较复杂的安装过程,或者Web应用程序来说,我个 ...
- Inno Setup for Windows service
Inno Setup for Windows service? up vote86down votefavorite 77 I have a .Net Windows service. I want ...
- 使用Inno SetUp脚本打包Winform程序
在开发桌面程序时,往往需要用到打包工具将程序打包为exe可执行文件. 之前在项目中用了下 InstallShield Limited Edition for Visual Studio 2015,它 ...
- INNO SETUP脚本向导创建的基本脚本
脚本范例分析:先来看看一段用INNO SETUP脚本向导创建的基本脚本的[Setup]段: [Setup] AppName=Premiere 6.5 汉化补丁-----------------(程 ...
- inno setup 脚本常用修改 转
http://blog.sina.com.cn/s/blog_72c2eb350100y2sa.html 有人提及想更换安装界面的图片,其实方法很简单,只需要修改inno setup安装目录下的Wiz ...
随机推荐
- oracle个人总结
oracle优化原则 1:insert 插入 (1):insert into /*+ append */ NOLOGGING 2: select 查询 (1):/*+ full(v) */ 全表查询 ...
- Spark(3) - External Data Source
Introduction Spark provides a unified runtime for big data. HDFS, which is Hadoop's filesystem, is t ...
- C#基础学习文章导航
第一部分:入个门 C#入门篇-1:HelloWorld的类 C#入门篇-2:什么是变量 C#入门篇-3:数据类型及转换 C#入门篇-4:使用运算符 第二部分:流程控制语句 C#入门篇5-1:流程控制语 ...
- HDU 1688 Sightseeing
题目链接:Sightseeing 题意:求最短路和比最短路长度+1的所有路径条数. 附代码:用数组记录最短和次短路径的长度和条数,一次更新,直到没有边可以更新. #include <stdio. ...
- TextBoxButton控件的开发实现
效果图: 实现代码: public TextBoxButton() { _button = new Button { ForeColor = System.Drawing.SystemColors.G ...
- 让你的WPF程序使用多线程——BackgroundWorker
在wpf中可以使用许多方法执行异步操作.利用.NET的芳芳就是手动创建一个新的System.Threading.Thread对象,提供一步代码,并使用THread.Start()方法加载代码.这种方法 ...
- Windows获取文件大小
Windows最初的设计允许我们处理非常大的文件,所以最初的设计者选用64位值来表示文件大小.但是我们在日常处理过程中文件大小一般不会超过4GB.故Windows提供了两个联合类型的数据结构表示文件大 ...
- Windows多线程编程总结
1 内核对象 1 .1 内核对象的概念 内核对象是内核分配的一个内存块,这种内存块是一个数据结构,表示内核对象的各种特征.并且只能由内核来访问.应用程序若需要访问内核对象,需要通过操作系统提供的函数来 ...
- checkbox全选功能
$("#cb_classType_all").change(function () { if ($(this).is(":checked")) { $(&quo ...
- IT公司100题-12-求1+2+…+n
问题描述: 求1+2+…+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句(A?B:C). 分析: 利用类的静态变量实现: new一含有n ...