1、調用DOS命令或批處理等其它命令列工具等Exec(ExpandConstant(‘{cmd}’), ‘/c dir c:\ >a.txt’,ExpandConstant(‘{app}’), SW_SHOWNORMAL, ewNoWait, ResultCode);
2、不顯示一些特定的安裝介面[code]function ShouldSkipPage(PageID: Integer): Boolean;beginif PageID=wpReady thenresult := 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到底是多少。
3、擷取SQLserver安裝路徑vardbpath:string;rtn:boolean;rtn := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\MSSQLServer\Setup','SQLPath', dbpath);if (!rtn) then dbpath := ExpandConstant('{app}');
4、擷取原生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';
5、檢查資料庫是否安裝//檢查是否已安裝SQLtryCreateOleObject('SQLDMO.SQLServer');exceptRaiseException('您還沒有安裝SQL資料庫.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');end;
6、根據環境變數選擇組件,擷取系統內容變數值見方法6procedure CurPageChanged(CurPageID: Integer);varpath:string;rtn:boolean;begin//MsgBox(inttostr(curpageid),mbInformation,mb_ok);if (curpageId =7) thenbeginrtn := checkTomcat6(path);if rtn then//如果系統以前沒安裝tomcat則選中組件,否則不選中beginWizardForm.ComponentsList.CheckItem(2,coUnCheck);WizardForm.ComponentsList.ItemEnabled[2] := false;end;end;end;
7、系統內容變數操作讀取:function GetEnv(const EnvVar: String): String;舉例:GetEnv('java_home')設定:[Setup]ChangesEnvironment=true[code]//環境變數名、值、是否安裝(刪除)、是否所有使用者有效procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall: Boolean);//設定環境變數函數varsOrgValue: string;x,len: integer;begin//得到以前的值RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)sOrgValue := Trim(sOrgValue);beginx := pos( Uppercase(aEnvValue),Uppercase(sOrgValue));len := length(aEnvValue);if aIsInstall then//是安裝還是反安裝beginif length(sOrgValue)>0 then aEnvValue := ';'+ aEnvValue;if x = 0 then Insert(aEnvValue,sOrgValue,length(sOrgValue) +1);endelsebeginif x>0 then Delete(sOrgValue,x,len);if length(sOrgValue)=0 thenbeginRegDeleteValue(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;
8、擷取NT服務安裝路徑Windows服務在系統安裝後會在註冊表的 "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\"下以服務的ServiceName建1個目錄,目錄中會有"ImagePath"舉例擷取tomcat6服務安裝路徑:RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\tomcat6','ImagePath', sPath);