Inno Setup for Windows service
Inno Setup for Windows service?
up vote86down votefavorite
77
|
I have a .Net Windows service. I want to create an installer to install that windows service. Basically, it has to do the following:
Also, I want to provide an uninstaller which runs the following command:
How to do these using Inno Setup?
c# windows-services inno-setup
|
||||
add a comment
|
4 Answers
up vote185down voteaccepted
|
You don't need Here is the way I'm doing it in my application:
Basically you can have your service to install/uninstall on its own by using Then it's just matter of adding into your InnoSetup script something like this:
|
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 安装、卸载前检测进程或服务
(2015-04-22 11:15:00)
标签:
innoinno打包issisapprunningpsvince.dll |
分类: 编程 |
1、32位程序的PSVince.dll插件方法。
[Files] Source: psvince.dll; Flags: dontcopy[Code] function IsModuleLoaded(modulename: AnsiString ): Boolean; external 'IsModuleLoaded@files:psvince.dll stdcall';
2、PSVince控件在64位系统(Windows 7/Server 2008/Server 2012)下无法检测到进程,使用下面的函数可以解决。
function IsAppRunning(const FileName : string): Boolean; varFSWbemLocator: Variant;FWMIService : Variant;FWbemObjectSet: Variant; beginResult := false;tryFSWbemLocator := 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;exceptif (IsModuleLoaded(FileName)) thenbeginResult := false;endelsebeginResult := true;endend; end;
这里,有可能存在异常:Exception: SWbemLocator:依赖服务或组件无法启动
解决办法参照如下步骤:
1.在命令提示行运行以下命令:
cd /d %windir%\system32\wbem
rename Repository Rep_bak
2.建一个.bat批处理文件并运行,内容如下:
Mofcomp C:\WINDOWS\system32\WBEM\cimwin32.mof
Mofcomp C:\WINDOWS\system32\WBEM\cimwin32.mfl
Mofcomp C:\WINDOWS\system32\WBEM\system.mof
Mofcomp C:\WINDOWS\system32\WBEM\wmipcima.mof
Mofcomp C:\WINDOWS\system32\WBEM\wmipcima.mfl
3.在命令提示行运行以下命令:
cd /d %windir%\system32\wbem
for %i in (*.mof,*.mfl) do Mofcomp %i
4.重新注册 WMI 组件,在命令提示行运行以下命令:
cd /d %windir%\system32\wbem
for %i in (*.dll) do RegSvr32 -s %i
for %i in (*.exe) do %i /RegServer
//安装,并在安装前检测程序是否在运行,如果运行先结束进程
function InitializeSetup(): Boolean; beginResult := true;if IsAppRunning('{#MyAppExeName}') thenbeginif MsgBox('安装程序检测到 {#MyAppName} 正在运行!'#13''#13'单击“是”按钮关闭程序并继续安装;'#13''#13'单击“否”按钮退出安装!', mbConfirmation, MB_YESNO) = IDYES thenbeginTaskKillProcessByName('{#MyAppExeName}');Result:= true;endelseResult:= false;end; end;
//卸载,与安装类似
function InitializeUninstall(): Boolean;beginResult:= true;if IsAppRunning('{#MyAppExeName}') thenbeginif MsgBox('卸载程序检测到 {#MyAppName} 正在运行!'#13''#13'单击“是”按钮关闭程序并继续卸载;'#13''#13'单击“否”按钮退出卸载!', mbConfirmation, MB_YESNO) = IDYES thenbeginTaskKillProcessByName('{#MyAppExeName}');Result:= true;endelseResult:= false;end;end;
Inno Setup for Windows service相关推荐
- Windows下使用Inno Setup 制作exe安装包
原文地址:点击打开链接 Inno Setup 详解中文资料 其一:使用教程 一.Inno Setup 是什么? InnoSetup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 19 ...
- Flutter桌面开发 — Windows App打包以及使用Inno Setup生成.exe文件安装包
文章目录 1 打包 Flutter Windows App 1.1 开发环境准备 1.2 支持Windows 1.3 构建Windows App 2 使用Inno Setup生成.exe文件安装包 2 ...
- 【Java】Java GUI制作Windows桌面程序,利用windowbuilder生成界面,使用exe4j打包成可执行文件,使用Inno Setup打包成安装包,超级详细教程
目录 1.GUI插件 1.1 下载GUI绘制插件 1.2 eclipse中配置windowbuilder插件 2.绘制GUI界面 2.1 建立一个GUI的项目 3.配置Maven项目 3.1新建一个M ...
- windows打包软件-Inno Setup
可执行程序需要打包之后发布. 在window上,可以使用Inno Setup进行打包.Inno Setup 是 Jordan Russell 和 Martijn Laan 为 Windows 程序提供 ...
- Windows EXE打包工具Inno Setup
Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞争力可能已经超过一些商业的安装程序制作软件.Inn ...
- windows安装包制作工具Inno Setup简介
Inno Setup简介 Inno Setup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Setup 今天在功能设置和稳定性上的竞争力可能已经超过一些商业 ...
- windows安装程序制作教程。《inno setup》可将多个安装程序打包成一个安装包,一次安装操作全部安装完成
1,下载 inno setup 官网地址:http://www.jrsoftware.org 下载地址:https://mlaan2.home.xs4all.nl/ispack/innosetup-5 ...
- Inno Setup 检测已安装的.NET Framework 版本
翻译自:http://kynosarges.org/DotNetVersion.html 由 Jordan Russell 写的 Inno Setup 是一个伟大的安装脚本程序,但缺乏一个内置的函数来 ...
- Inno Setup 介绍
Inno Setup 详解中文资料 其一:使用教程 一.Inno Setup 是什么? InnoSetup 是一个免费的 Windows 安装程序制作软件.第一次发表是在 1997 年,Inno Se ...
- inno setup使用1 记录一下相关参数
Inno Setup的使用.这个是来自程序自己有使用帮助.这一部分到Setup section.这个也是东西最多的section.现在都还只是翻译,以后会增加相应的效果. Inno setup 用is ...
最新文章
- 搭建网站服务器是选择高配置还是选择性能稳定?
- java jediscluster_方便jediscluster操作的工具类
- wxWidgets:wxPython 概述
- python 操作ps_使用Python分离出ps的输出
- Behavior Designer笔记
- 2108 ACM 向量积 凹凸
- dict python用法_Python_Dict用法梳理
- 阿拉伯数字转中文小写数字
- 简单工厂和策略模式结合
- Serverless 实战 —— Serverless + Egg.js 后台管理系统实战
- php域运算符号,PHP中的域运算符号是()。
- 最课程学员启示录:一份有诚意的检讨书
- android toast 自定义时间,android自定义Toast设定显示时间
- 关于web中的自适应布局
- 简单测试.NET开源的PDF文档生成器QuestPDF
- vivo手机安装应用提示未安装
- 美苏太空竞赛历年卫星火箭发射以及历史事件介绍
- 以IM为例看58同城典型技术架构演变
- 今天去了海淀基督教堂
- python编码大全_Python3中的编码转换大全(不定期更新)
热门文章
- 作为前端程序员,你不能不知道的这个小技巧
- git还原历史版本代码
- SHELL 读取文件的每一行内容并输出
- Yii2修改默认控制器
- qca9377linux无线驱动,ubuntu下安装无线网卡去驱动Qualcomm-Atheros-QCA9377
- LINUX清理垃圾桶提示“没有权限”或“目录非空”
- 编程基本功:典型的柳氏风格命名一例
- 龙芯的JDK非常慢,准备分析一下
- configure: error: Library requirements (libpcre >= 7.8) not met
- LINUX虚拟机安装增强功能时报错:/sbin/mount.vboxsf: mounting failed with the error: No such device