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);
解决安装客户需要重启:
[Code] //不重启 function InitializeSetup(): Boolean; var ResultCode: Integer; begin Result := False; if ParamCount <= 1 then Exec(ExpandConstant('{cmd}'), ExpandConstant('/c ""{srcexe}"" /sp- /norestart'), '', SW_HIDE, ewNoWait, ResultCode) else Result := True; end;
跳过 INNO 安装程序的“欢迎”页面 在脚本中添加[Code]如下 [Code] //跳过 INNO 安装程序的“欢迎”页面 const WM_LBUTTONDOWN = 513; WM_LBUTTONUP = 514; procedure InitializeWizard(); begin PostMessage(WizardForm.NextButton.Handle,WM_LBUTTONDOWN,0,0); PostMessage(WizardForm.NextButton.Handle,WM_LBUTTONUP,0,0); // 选择单选框NO不重启按钮 WizardForm.YesRadio.Checked := FALSE; WizardForm.NoRadio.Checked := TRUE; end;
要求是WINDOWS管理员身份才能安装客户端(支持XP以上全部系统)
[Setup] PrivilegesRequired=admin 通过psvince.dll插件判断MEETING是否正在运行 先复制psvince.dll到Inno Setup 安装目录,然后添加代码。 [Files] ;判断进程用DLL文件(邮件附件) Source: compiler:psvince.dll; Flags: dontcopy noencryption [Code] //增加判断是否存在程序-------------------------------------------------------- function IsModuleLoaded(modulename: String ): Boolean; external 'IsModuleLoaded@files:psvince.dll stdcall'; function InitializeSetup(): boolean; var IsAppRunning: boolean; begin Result:= true; IsAppRunning:= IsModuleLoaded('ActiveMeeting.exe'); //程序文件名 while IsAppRunning do begin if MsgBox('网动视频会议系统 正在运行,继续安装前请先关闭它!'#13'强烈建议您先【关闭程序】,再进行安装' #13#13 '要继续安装吗?', mbConfirmation, MB_OKCANCEL) = IDOK then IsAppRunning:= IsModuleLoaded('ActiveMeeting.exe') //程序文件名 else begin IsAppRunning:= false; Result:= false; end; end; end;