Inno setup常用代碼補充【收藏】

來源:互聯網
上載者:User
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);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.