使用Installshield制作asp,asp.net應(yīng)用的安裝程序
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
在使用asp,asp.net編寫Web應(yīng)用時,最大的煩惱莫過于程序的分發(fā)的部署,由于面向的最終用戶,所以程序的安裝的過程必須要簡單,方便和快捷。 下面提供了Installshield的腳本,改腳本功能包括: 1,檢測IIS是否安裝 2,檢測IE版本 3,自動建立SQL數(shù)據(jù)庫 4,自動建立IIS虛擬目錄 5,能讀取注冊表和INI文件 6,注冊.dll組件 應(yīng)用程序開發(fā)環(huán)境:Windows2000+VS 2003+SQL2000 制作安裝程序環(huán)境:Installshield7.0(其實6.22以上都可以,只是中文語言包太難找,所以就用7.0了,另7.0界面也好看多了,XP風(fēng)格) //////////////////////////////////////////////////////////////////////////////// // // File Name: Setup.rul // // Description: InstallShield script // // Comments: This script was generated based on the selections you made in // the Project Wizard. Refer to the help topic entitled "Modify // the script that the Project Wizard generates" for information // on possible next steps. // //////////////////////////////////////////////////////////////////////////////// // Include header files #include "ifx.h" ////////////////////// string defines //////////////////////////// number xx1,xx2; //////////////////// installation declarations /////////////////// // ----- DLL function prototypes ----- // your DLL function prototypes // ---- script function prototypes ----- // your script function prototypes prototype CreateDataBase(STRING,STRING,STRING);//附加數(shù)據(jù)庫 prototype CheckIIS(); //檢測是否安裝了iis prototype Checkie(); //檢測ie版本 prototype Checkmdac(); //檢測mdac版本 prototype regcom(); //注冊jamil組件 // prototype deliis(STRING);//刪除虛擬目錄 prototype Writeini(STRING,STRING,STRING); prototype DelDataBase(STRING,STRING,STRING); // your global variables ////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnFirstUIBefore // // EVENT: FirstUIBefore event is sent when installation is run for the first // time on given machine. In the handler installation usually displays // UI allowing end user to specify installation parameters. After this // function returns, FeatureTransferData is called to perform file // transfer. // /////////////////////////////////////////////////////////////////////////////// function OnFirstUIBefore() // number nResult,nSetupType; // string szTitle, szMsg; // string szLicenseFile, szQuestion; // string szName, szCompany; // string szTargetPath; // string szDir; // string szFeatures, szTargetdir; // number nLevel; // LIST listStartCopy; //number nvSize; //number nUser; number nResult,nSetupType; string szTitle, szMsg; string szLicenseFile, szQuestion; string szName, szCompany, szSerial; string szFeatures, szTargetdir; number nLevel; LIST listStartCopy,list; number nvSize; number nUser; number nOpt,svEdit1,svEdit2; STRING szServerIP,szServerPort,szServerIPDefault,szServerPortDefault; STRING szSQLsvr,szSQLusr,szSQLpwd,svSQLsvr,svSQLusr,svSQLpwd; STRING svName, svCompany, svSerial; STRING szFile,szTargetPath,szDir,szfolder; STRING szField1,szField2; STRING szDefault,svResult; string szComponents; OBJECT piisObj; STRING szTitle1; STRING szMsg1,szMsg2; STRING szMsg11, szMsg12, szOpt1, szOpt2; BOOL bvOpt1, bvOpt2; begin // TO DO: if you want to enable background, window title, and caption bar title //SetTitle( @PRODUCT_NAME, 24, WHITE ); // SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION ); // Enable( FULLWINDOWMODE ); // Enable( BACKGROUND ); // SetColor(BACKGROUND,RGB (0, 128, 128)); //SetFont (FONT_TITLE, STYLE_NORMAL, "宋體"); SHELL_OBJECT_FOLDER = @PRODUCT_NAME; nSetupType = TYPICAL; szDir = INSTALLDIR; szName = ""; szCompany = ""; Dlg_Start: // beginning of dialogs label Dlg_SdWelcome: szTitle = ""; szMsg = ""; nResult = SdWelcome( szTitle, szMsg ); if (nResult = BACK) goto Dlg_Start; Dlg_SdLicense: szLicenseFile = SUPPORTDIR ^ "license.txt"; szTitle = ""; szMsg = ""; szQuestion = ""; nResult = SdLicense( szTitle, szMsg, szQuestion, szLicenseFile ); if (nResult = BACK) goto Dlg_SdWelcome; Dlg_SdCustomerInformation: szMsg = ""; szTitle = ""; nResult = SdCustomerInformation( szTitle, szName, szCompany, nUser ); if (nResult = BACK) goto Dlg_SdLicense; Dlg_SdAskDestPath: szTitle = ""; szMsg = ""; nResult = SdAskDestPath( szTitle, szMsg, szDir, 0 ); INSTALLDIR = szDir; if (nResult = BACK) goto Dlg_SdCustomerInformation; Dlg_SelMode ://設(shè)置數(shù)據(jù)庫服務(wù)器 對話框 szTitle = "是否安裝.net框架"; szMsg = "是否要安裝.net框架,如果已經(jīng)安裝了.net框架則不需要安裝。"; szField1="我要安裝.net框架。"; szField2="我已經(jīng)安裝了,不需要再安裝。"; svEdit1=TRUE; svEdit2=FALSE; SetDialogTitle(DLG_ASK_TEXT,szTitle); //DialogSetInfo ( DLG_INFO_CHECKSELECTION, "", 1); nOpt = EXCLUSIVE ; nResult = AskOptions (nOpt,szMsg,szField1,svEdit1,szField2,svEdit2); if (nResult = BACK) goto Dlg_SdAskDestPath; if (svEdit1=TRUE)then if Checkmdac() then//如果已經(jīng)安裝則跳過 if(LaunchAppAndWait (SUPPORTDIR^"mdac_typ.exe","",WAIT)<0) then MessageBox ("安裝微軟數(shù)據(jù)訪問組件是發(fā)生以外,請重新安裝。",SEVERE); goto Dlg_SelMode; endif; endif; if(LaunchAppAndWait ( SUPPORTDIR ^"dotnetfx.exe " , "" ,WAIT)<0) then MessageBox ("安裝.net框架時發(fā)生意外,請重新安裝。",SEVERE); goto Dlg_SelMode; endif; endif; Dlg_SetupType: szTitle = ""; szMsg = ""; nResult = SetupType ( szTitle , szMsg , "" , nSetupType , 0 ); if (nResult = BACK) then goto Dlg_SdAskDestPath; else nSetupType = nResult; if (nSetupType != CUSTOM) then szTargetPath = INSTALLDIR; nvSize = 0; FeatureCompareSizeRequired(MEDIA,szTargetPath,nvSize); if (nvSize != 0) then MessageBox( szSdStr_NotEnoughSpace, WARNING ); goto Dlg_SetupType; endif; endif; endif; Dlg_SdFeatureTree: if ((nResult = BACK) && (nSetupType != CUSTOM)) goto Dlg_SetupType; szTitle = ""; szMsg = ""; szTargetdir = INSTALLDIR; szFeatures = ""; nLevel = 2; if (nSetupType = CUSTOM) then nResult = SdFeatureTree(szTitle, szMsg, szTargetdir, szFeatures, nLevel); if (nResult = BACK) goto Dlg_SetupType; endif; Dlg_AskText ://設(shè)置數(shù)據(jù)庫服務(wù)器 對話框 szTitle = "設(shè)置IIS信息服務(wù)及數(shù)據(jù)庫服務(wù)器"; szMsg = "現(xiàn)在開始設(shè)置IIS系統(tǒng)"; szQuestion=" 請輸入本服務(wù)器的主機名或IP地址,安裝程序?qū)凑漳峁┑馁Y料設(shè)置IIS信息服務(wù)。如果您沒有填寫,安裝程序?qū)⒆詣犹^站點的創(chuàng)建!"; szServerIP="地址:"; szServerPort="端口:"; szServerIPDefault="192.168.0.1"; szServerPortDefault="80"; SetDialogTitle(DLG_ASK_TEXT,szTitle); nResult=SdShowDlgEdit2 (szTitle, szQuestion,szServerIP,szServerPort,szServerIPDefault,szServerPortDefault); if (nResult = BACK) goto Dlg_SetupType; Dlg_AskSQL ://設(shè)置數(shù)據(jù)庫服務(wù)器 對話框 szTitle = "設(shè)置數(shù)據(jù)庫"; szMsg = "現(xiàn)在開始設(shè)置數(shù)據(jù)庫系統(tǒng)"; szQuestion=" 請輸入數(shù)據(jù)庫服務(wù)器的用戶名和密碼,安裝程序?qū)凑漳喜教峁┑腎P地址和下面的用戶名和密碼創(chuàng)建和優(yōu)化數(shù)據(jù)庫系統(tǒng)。如果您提供的用戶名和密碼是錯誤的,安裝程序?qū)⒆詣犹^數(shù)據(jù)的設(shè)置!"; //szSQLsvr="主機名:"; szSQLusr="用戶名:"; szSQLpwd="密碼:"; //svSQLsvr="localhost"; svSQLusr="sa"; svSQLpwd=""; SetDialogTitle(DLG_ASK_TEXT,szTitle); nResult=SdShowDlgEdit2 (szTitle, szQuestion,szSQLusr,szSQLpwd,svSQLusr,svSQLpwd); if (nResult = BACK) goto Dlg_AskText; Dlg_SdStartCopy: szTitle = ""; szMsg = ""; szTitle1 = "安裝失敗"; szMsg11 = "由于安裝時發(fā)生意外導(dǎo)致安裝失敗"; szMsg12 = "點擊完成退出安裝。"; szOpt1 = ""; szOpt2 =""; listStartCopy = ListCreate( STRINGLIST ); ListAddString(listStartCopy,"用戶名:"+szName,AFTER); ListAddString(listStartCopy,"公司名稱:"+szCompany,AFTER); ListAddString(listStartCopy,"目標目錄:"+szDir,AFTER); if (svEdit1=TRUE) then ListAddString(listStartCopy,"IP地址:"+szServerIPDefault,AFTER); ListAddString(listStartCopy,"端口號:"+szServerPortDefault,AFTER); endif; ListAddString(listStartCopy,"請確認您填寫的信息,按下一步開始復(fù)制文件",AFTER); // listStartCopy = ListCreate( STRINGLIST ); //The following is an example of how to add a string(szName) to a list(listStartCopy). //eg. ListAddString(listStartCopy,szName,AFTER); nResult = SdStartCopy( szTitle, szMsg, listStartCopy ); ListDestroy(listStartCopy); if (nResult = BACK) goto Dlg_SdFeatureTree; Enable(STATUSEX); if CheckIIS() then if(xx1=2) goto Dlg_AskText; //判斷站點是否建立成功 // regcom();//注冊組件 CreateDataBase(szServerIPDefault,svSQLusr,svSQLpwd); // 創(chuàng)建和 優(yōu)化數(shù)據(jù)庫 Writeini(szServerIPDefault,svSQLusr,svSQLpwd);//寫ini文件 else MessageBox ("你的計算機沒有安裝IIS!請安裝后重試!",SEVERE); endif; return 0; end; /////////////////////////////////////////////////////////////////////////////// // // FUNCTION: OnMaintUIBefore // // EVENT: MaintUIBefore event is sent when end user runs installation that // has already been installed on the machine. Usually this happens // through Add/Remove Programs applet. In the handler, installation // usually displays UI allowing end user to modify existing installation // or uninstall application. After this function returns, // FeatureTransferData is called to perform file transfer. // /////////////////////////////////////////////////////////////////////////////// function OnMaintUIBefore() NUMBER nResult, nType; STRING szTitle, szMsg, svDir, svResult, szCaption; STRING svip,svuser,svpass; begin // TO DO: if you want to enable background, window title, and caption bar title // SetTitle( @PRODUCT_NAME, 24, WHITE ); // SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION ); // SetColor(BACKGROUND,RGB (0, 128, 128)); // Enable( FULLWINDOWMODE ); // Enable( BACKGROUND ); Dlg_Start: Disable(BACKBUTTON); nType = SdWelcomeMaint(szTitle, szMsg, MODIFY); Enable(BACKBUTTON); if (nType = REMOVEALL) then svResult = SdLoadString(IFX_MAINTUI_MSG); szCaption = SdLoadString(IFX_ONMAINTUI_CAPTION); nResult = SprintfBox(MB_OKCANCEL,szCaption,"%s",svResult); if (nResult = IDCANCEL) goto Dlg_Start; endif; nResult = NEXT; Dlg_SdFeatureTree: if (nType = MODIFY) then szTitle = ""; szMsg = ""; nResult = SdFeatureTree(szTitle, szMsg, INSTALLDIR, "", 2); if (nResult = BACK) goto Dlg_Start; endif; switch(nType) case REMOVEALL: FeatureRemoveAll(); case REPAIR: FeatureReinstall(); endswitch; GetProfString (SystemFolder^"dbconn.ini", "dbconnection","ip", svip); GetProfString (SystemFolder^"dbconn.ini", "dbconnection","db_user", svuser); GetProfString (SystemFolder^"dbconn.ini", "dbconnection","db_pass", svpass); //svall=svip+","+svuser+","+svpass; // SdShowMsg(svall,WAIT); // Delay(5); DelDataBase(svip,svuser,svpass); DeleteFile (INSTALLDIR^"database\\kill.out"); Enable(STATUSEX); end; ////////////////////////// // 創(chuàng)建和優(yōu)化數(shù)據(jù)庫 ////////////////////////// function CreateDataBase(svSQLsvr,svSQLusr,svSQLpwd) STRING szCmdLine1,szWaitTxt,szdatabase,szdatabase1,path,path1,path3; begin path=INSTALLDIR^"database\\fenoffice.mdf"; path3=INSTALLDIR^"database\\fenoffice_log.ldf"; szWaitTxt=" 正在創(chuàng)建數(shù)據(jù)庫...."; SdShowMsg (szWaitTxt, TRUE); Delay(2); //CopyFile(SUPPORTDIR^"kill.sql",INSTALLDIR^"database\\kill.sql"); CopyFile(SUPPORTDIR^"fenoffice.mdf",INSTALLDIR^"database\\fenoffice.mdf"); CopyFile(SUPPORTDIR^"fenoffice_log.ldf",INSTALLDIR^"database\\fenoffice_log.ldf"); //szCmdLine="hello"; szdatabase = "/U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q \"exec sp_attach_db N'fenoffice' , N'"+path+"',N'"+path3+"'\""; //SdShowMsg(szdatabase,WAIT); //Delay(3); if (LaunchAppAndWait("osql.exe", szdatabase,WAIT)<0) then; MessageBox ("數(shù)據(jù)庫創(chuàng)建失敗!請確您的系統(tǒng)中已安裝 Microsoft SQL Server 2000.\n如仍無法解決,請聯(lián)系系統(tǒng)供應(yīng)商!",SEVERE); endif; path1=INSTALLDIR^"database"; //szdatabase1=" -S "+svSQLusr+" -U "+svSQLusr+" -P "+svSQLpwd+" -d master -n -i "+path1+"\\kill.sql -o "+path1+"\\kill.out"; //SdShowMsg(szdatabase2,WAIT); //Delay(3); if (LaunchAppAndWait("osql.exe", szdatabase1,WAIT)<0) then MessageBox ("配置數(shù)據(jù)庫失敗!請嘗試手動配置!",SEVERE); endif; SdShowMsg (szWaitTxt, FALSE); return 0; end; // // //檢測是否安裝了iis // // function CheckIIS() NUMBER nvType, nvSize; STRING svvalue; begin RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE ); if (RegDBKeyExist ("System\\CurrentControlSet\\Services\\IISADMIN" ) = 1) then return (1); else return (0); endif; end; // // //檢測ie的版本 // // function Checkie() NUMBER nvType, nvSize; STRING svvalue,szKey,szName; begin szKey="SOFTWARE\\Microsoft\\Internet Explorer"; szName="version"; RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE ); RegDBGetKeyValueEx(szKey, szName, nvType, svvalue, nvSize ); if(svvalue="6.0.2600.0000")then return (0); else return (1); endif; end; // //檢測mdac的版本 // // function Checkmdac() NUMBER nvType, nvSize; STRING svvalue,szKey,szName; begin szKey="SOFTWARE\\Microsoft\\DataAccess"; szName="version"; RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE ); RegDBGetKeyValueEx(szKey, szName, nvType, svvalue, nvSize ); if(svvalue="2.71.9030.9") then return (0); else return (1); endif; end; // // //Write dbconn.ini file // // function Writeini(svSQLsvr,svSQLusr,svSQLpwd) string svDate,iniFile,svResult,szInfo,szWaitTxt; NUMBER nvResult; begin //szWaitTxt="正在配置系統(tǒng)文件,請稍侯...."; iniFile =SUPPORTDIR^"dbconn.ini"; //SdShowMsg (szWaitTxt, TRUE); // Delay(2); if (GetSystemInfo (DATE, nvResult, svResult) < 0) then szInfo = "不能得到系統(tǒng)時間"; else svDate=svResult+" "; endif; if (GetSystemInfo (TIME, nvResult, svResult) < 0) then szInfo = "不能得到系統(tǒng)時間"; else svDate=svDate+svResult; endif; if (WriteProfString(iniFile,"dbconnection","server", svSQLsvr) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"dbconnection","ip", svSQLsvr) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"dbconnection","db_user",svSQLusr) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"dbconnection","db_pass",svSQLpwd) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"dbconnection","database", "fenoffice") <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"webwork","webworkstart", svDate) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; if (WriteProfString(iniFile,"webwork","webworkpath", INSTALLDIR) <0) then MessageBox("dbconn.ini錯誤,系統(tǒng)將無法運行!", SEVERE); endif; CopyFile(SUPPORTDIR^"dbconn.ini",SystemFolder^"dbconn.ini"); end; // //注冊組件 // function regcom() string szLine,szWaitTxt; begin szLine=SystemFolder^"jmail.dll"; szWaitTxt=" 正在注冊組件...."; SdShowMsg (szWaitTxt, TRUE); Delay(2); CopyFile(SUPPORTDIR^"jmail.dll",SystemFolder^"jmail.dll"); if (LaunchAppAndWait("regsvr32.exe",szLine,WAIT)<0) then MessageBox ("注冊組件失敗,請嘗試手動注冊"+szLine,SEVERE); // else // MessageBox ("注冊組件成功!"+szLine,INFORMATION); //SdShowMsg (szLine, TRUE); // Delay(3); endif; end; //function deliis(VirtualFolder) //STRING szCmdLine; //begin //刪除已經(jīng)存在的虛擬目錄 // szCmdLine = SUPPORTDIR ^"adsutil.vbs delete w3svc/1/root/"^VirtualFolder; // if(LaunchAppAndWait("CScript.exe", szCmdLine, WAIT)<0) then // MessageBox ("設(shè)置iis信息服務(wù)失敗,請嘗試手動配置!",INFORMATION); // endif; //end; // //刪除數(shù)據(jù)庫 // // function DelDataBase(server,user,pass) STRING szWaitTxt,szdatabase1,szdatabase2,szdatabase3,path1; begin szWaitTxt=" 正在刪除數(shù)據(jù)庫...."; szdatabase2 = "/U "+user+" /P "+pass+" /Q \" exec killspid N'fenoffice'"; LaunchAppAndWait("osql.exe", szdatabase2,WAIT); //SdShowMsg(szdatabase2,WAIT); //Delay(3); szdatabase3 = "/U "+user+" /P "+pass+" /Q \" exec sp_dbremove N'fenoffice'" ; LaunchAppAndWait("osql.exe", szdatabase3,WAIT); //SdShowMsg(szdatabase3,WAIT); //Delay(3); SdShowMsg (szWaitTxt, FALSE); return 0; end; 該文章在 2010/8/19 23:57:35 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |