杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2597|回复: 0

InstallShield制作的打包程序——代码示例

[复制链接]
发表于 2018-5-24 17:04:36 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
1、Setup.Rul

  1. //===========================================================================  
  2. //  
  3. //  File Name:    Setup.rul  
  4. //  
  5. //  Description:  Blank setup main script file  
  6. //  
  7. //  Comments:     Blank setup is an empty setup project. If you want to  
  8. //                create a new project via. step-by step instructions use the  
  9. //                Project Assistant.  
  10. //  
  11. //描述:空白设置主脚本文件  
  12. // 评论:空白的设置是一个空的安装项目。如果你想通过创建一个新的项目。分步说明使用项目助理  
  13. //===========================================================================  
  14.   
  15. // Included header files ----------------------------------------------------  
  16. #include "ifx.h"  
  17.    BOOL bWinLogin;     
  18.    string szServer, szUser, szPassword;   
  19.    //---------------------------------------------------------------   
  20. prototype  WriteDBInfo(STRING);  
  21. function  WriteDBInfo(dbConnection)      
  22.     string svResult;     
  23.     number nvFileHandle;  
  24. begin  
  25.   
  26. //写获取连接数据库文件  
  27.     OpenFileMode(FILE_MODE_APPEND);   
  28.     if (FindFile(ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库","DBConnection.txt", svResult) < 0) then //没有,需要create一个   
  29.         CreateFile(nvFileHandle,ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库","DBConnection.txt");   
  30.     else   
  31.         OpenFile (nvFileHandle ,ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库","DBConnection.txt");     
  32.     endif;   
  33.     WriteLine( nvFileHandle,dbConnection);   
  34.     CloseFile(nvFileHandle);   
  35. end ;  
  36. /////////////////////////////////////////////////////////////////////////////////////////////////  
  37. prototype DetachDB();  
  38. function number DetachDB()   
  39.     STRING szCmdLine,szWaitTxt;   
  40.     string svResult,svLine;     
  41.     number nvFileHandle;  
  42. begin      
  43.     OpenFileMode(FILE_MODE_APPEND);   
  44.     szWaitTxt=" 正在分离安装网站使用的数据库……";   
  45.     SdShowMsg (szWaitTxt, TRUE);   
  46.     Delay(2);      
  47.     //szCmdLine = "/E  /S "+svSQLsvr+" /Q /"EXEC  sp_detach_db  @dbname  =  N'YCSCMDB'";   
  48.     //读取连接字符串   
  49.     if (FindFile(ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库","DBConnection.txt", svResult) <0) then   
  50.        MessageBox ("数据库配置文件丢失,请手动分离或删除网站使用的数据库!",SEVERE);   
  51.     else  
  52.         OpenFile ( nvFileHandle ,ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库","DBConnection.txt");      
  53.         ab:  
  54.         if(GetLine( nvFileHandle,svLine)<0) then   
  55.             CloseFile(nvFileHandle);  
  56.          else  
  57.                 szCmdLine =svLine+" /Q /"EXEC  sp_detach_db  @dbname  =  N'YCSCMDB'/"";   
  58.                 //szCmdLine = "/U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q /"EXEC  sp_attach_db  @dbname  =  N'dlbj',@filename1  = N'"+TARGETDIR ^"dlbj_web.MDF',@filename2  = N'"+TARGETDIR ^"dlbmydb_log.LDF'/"";   
  59.                 LaunchAppAndWait("osql.exe", szCmdLine,WAIT);  
  60.                 if(LaunchAppAndWait("osql.exe", szCmdLine,WAIT)<0)  then  
  61.                       MessageBox ("数据库分离失败!请手动分离或删除网站使用的数据库!",SEVERE);   
  62.                    else  
  63.                        goto ab;  
  64.                 endif;   
  65.         endif;  
  66.         SdShowMsg (szWaitTxt, FALSE);         
  67.     endif;   
  68.   
  69.     //szWaitTxt=" 正在优化系统数据库……";   
  70.     //SdShowMsg (szWaitTxt, TRUE);   
  71.     //Delay(2);   
  72.     //szCmdLine = "/U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q /"use dlbj ; exec sp_updatestats/"";   
  73. //  if (LaunchAppAndWait("osql.exe", szCmdLine,WAIT) < 0) then   
  74. //  MessageBox ("数据库优化失败!您可以在 sql查询分析器中执行 use dlbj ; exec sp_updatestats 完成!",SEVERE);   
  75. //  endif;   
  76. //  SdShowMsg (szWaitTxt, FALSE);   
  77.       
  78.     return 0;   
  79.   
  80. end;   
  81. //---------------------------------------------------------------------------  
  82.      
  83. // Note: In order to have your InstallScript function executed as a custom  
  84. // action by the Windows Installer, it must be prototyped as an   
  85. // entry-point function.  
  86.   
  87. // The keyword export identifies MyFunction() as an entry-point function.  
  88. // The argument it accepts must be a handle to the Installer database.  
  89.       
  90. /* export prototype MyFunction(HWND); */  
  91. //注意:为了让您的InstallScript中作为一个自定义的执行   
  92. //由Windows Installer的行动,它必须作为一个原型 入口点函数。   
  93.   
  94. //关键字出口标识调用MyFunction()作为入口点函数。   
  95. //它接受的参数必须是一个句柄安装程序数据库。   
  96.       
  97. //*出口原型调用MyFunction(HWND); * /  
  98.       
  99.       //-----------------------------------------------------------------------  
  100. prototype CheckIIS(); //检测是否安装了iis      
  101. //--------------------------------------------------------   
  102. //检测是否安装了IIS  
  103. function CheckIIS()   
  104.     NUMBER nvType, nvSize;   
  105.     STRING svvalue;   
  106.     begin   
  107.         RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );   
  108.         if (RegDBKeyExist ("System//CurrentControlSet//Services//IISADMIN" ) = 1) then   
  109.                 return (1);   
  110.             else   
  111.                 return (0);   
  112.         endif;  
  113.     end;   
  114. //-----------------------------------------------------------   
  115.       
  116. //---------------------------------------------------------------------------  
  117. // OnFirstUIBefore  
  118. //  
  119. // The OnFirstUIBefore event is called by the framework when the setup is  
  120. // running in first install mode. By default this event displays UI allowing  
  121. // the end user to specify installation parameters.  
  122. //该事件被称为OnFirstUIBefore由框架时,安装程序  
  123. //运行在第一次安装模式。允许默认情况下此事件显示界面  
  124. //最终用户指定安装参数。  
  125. //---------------------------------------------------------------------------  
  126. function OnFirstUIBefore()  
  127.     NUMBER nResult, nSetupType, nvSize, nUser;  
  128.     STRING szTitle, szMsg, szQuestion, svName, svCompany, szFile;  
  129.     STRING szLicenseFile;   
  130.       
  131.     LIST list, listStartCopy;  
  132.     BOOL bCustom;     
  133.     STRING szBmpPath, szAppPath,svResult,svLine,svSubStr,szIp;//自定义      
  134.     number nvFileHandle,nvIp;      
  135.     string szOpt1, szOpt2;      
  136.     BOOL bLicenseAccepted;  
  137. begin     
  138.     // TO DO: if you want to enable background, window title, and caption bar title                                                                     
  139.     // SetTitle( @PRODUCT_NAME, 24, WHITE );                                          
  140.     // SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION );                        
  141.     // Enable( FULLWINDOWMODE );                             
  142.     // Enable( BACKGROUND );                                
  143.     // SetColor(BACKGROUND,RGB (0, 128, 128));                       
  144.   
  145.     SHELL_OBJECT_FOLDER = @PRODUCT_NAME;         
  146.       
  147.     nSetupType = TYPICAL;     
  148. //-----------------------------------------------------------------------  
  149. //设置背景图片   
  150.       SetTitle("欢迎您使用银河卡电子产品",   24,   WHITE);                                                                                    
  151.           SetTitle( "安装“网上阅卷系统”",0,BACKGROUNDCAPTION);                                             
  152.           Enable(FULLWINDOWMODE);           
  153.           Enable(BACKGROUND );         
  154.          // PlaceBitmap   (SUPPORTDIR^"BackGround.bmp",0,0,0,UPPER_LEFT);  //左上角显示图片  
  155.          // PlaceBitmap   (SUPPORTDIR^"BackGround.bmp",0,0,0,FULLSCREENSIZE);   //全屏显示图片  
  156.          //PlaceWindow ( BILLBOARD , 200 , 40 , UPPER_LEFT ); //平铺logo   
  157.          //SetDisplayEffect(EFF_FADE);//设置显示效果     
  158.          // PlaceWindow   (   BILLBOARD   ,   200   ,   40   ,   UPPER_LEFT   );   
  159.          //PlaceWindow(BACKGROUND,10,10,UPPER_LEFT); //背景窗口的位置为左上方开始10,10   
  160.           SetColor(BACKGROUND,RGB   (0,   128,   128));   
  161. //----------------------------------------------------------------     
  162. //----------------------------------------------------------------     
  163. szBmpPath=SUPPORTDIR+"//left.bmp;1;0,0,0";  //图片有白色的背景,所以设置白色为透明色  “位图文件名;透明标志;<未用>;<未用>;透明色”标准位图为57×53  
  164. //SizeWindow (METAFILE,50, 50);     
  165. DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath,TRUE); // 设置左边的logo图片   
  166. //------------------------------------------------------------------     
  167. //------------------------------------------------------------------     
  168.   
  169. SdShowMsg( "安装程序正在检测系统必备组件...... ",TRUE);   
  170. Delay(2);      
  171. SdShowMsg   ("",FALSE);      
  172. //---------------------------------------------------------------------  
  173. WriteIp:  
  174. //写获取ip地址文件  
  175.     OpenFileMode(FILE_MODE_APPEND);   
  176.     if (FindFile(SUPPORTDIR,"ipconfig.bat", svResult) < 0) then //没有,需要create一个   
  177.         CreateFile(nvFileHandle,SUPPORTDIR,"ipconfig.bat");   
  178.     else   
  179.         OpenFile ( nvFileHandle ,SUPPORTDIR,"ipconfig.bat");     
  180.         //LaunchAppAndWait("","net stop w3svc"+"/S",WAIT);  
  181.     endif;   
  182.     WriteLine( nvFileHandle,"ipconfig /all >> /""+SUPPORTDIR+"/ipconfig.txt/"");   
  183.     CloseFile(nvFileHandle);   
  184.       LaunchAppAndWait("",SUPPORTDIR^"ipconfig.bat",WAIT);   
  185. //----------------------------------------------------------------------------------  
  186. //读取ip地址  
  187.     if (FindFile( SUPPORTDIR,"ipconfig.txt", svResult) < 0) then //没有,需要create一个   
  188.        goto WriteIp;  
  189.     else   
  190.         OpenFile ( nvFileHandle ,SUPPORTDIR,"ipconfig.txt");     
  191.     endif;   
  192.     ab:  
  193.     if(GetLine( nvFileHandle,svLine)<0) then   
  194.         CloseFile(nvFileHandle);  
  195.         else   
  196.         nvIp=StrFind(svLine,"Ethernet adapter 本地连接:");  
  197.         if(nvIp>-1)then   
  198.                     cd:  
  199.                     if(GetLine( nvFileHandle,svLine)<0) then   
  200.                         CloseFile(nvFileHandle);  
  201.                     else   
  202.                         nvIp=StrFind (svLine,"IP Address");  
  203.                          if(nvIp>-1)then   
  204.                            StrSub (svSubStr, svLine,nvIp+StrLength("IP Address. . . . . . . . . . . . : "), StrLength (svLine)-nvIp+StrLength("IP Address. . . . . . . . . . . . : "));   
  205.                            szIp=svSubStr;  
  206.                         else  
  207.                              goto cd;   
  208.                          endif;   
  209.                     endif;   
  210.             else  
  211.              goto ab;   
  212.          endif;   
  213.     endif;  
  214. //--------------------------------------------------------------------------------------  
  215. SetIIS:  
  216. //安装iis   
  217. //szProgram = "rundll32.exe";   
  218. //szCmdLine = "setupapi.dll,InstallHinfSection Modem1 132 " + WINDIR + "driver139//oxser.inf";  
  219. if CheckIIS()   then      
  220.     goto SetDotNet;  
  221. else      
  222.     SprintfBox(MB_OK,"IIS安装","您还未安装IIS,请安装!");      
  223.     if(LaunchAppAndWait("rundll32.exe", "shell32.dll,Control_RunDLL appwiz.cpl,,2", WAIT)<0)then  
  224.         SprintfBox(MB_OK,"IIS安装","IIS安装时发生意外,请重新安装!");   
  225.         else  
  226.         goto SetIIS;  
  227.     endif;   
  228. endif;  
  229. //---------------------------------------------------------------------------  
  230. SetDotNet:  
  231. //判断是否安装了.netframework  
  232. RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );  
  233. if ( RegDBKeyExist ("SOFTWARE//Microsoft//.NETFramework//policy//v2.0" ) < 0) then  
  234. SprintfBox(MB_OK,".NET安装","尚未安装.net framework 2.0 !/n请点击“确定”以继续安装!");         
  235. if( LaunchAppAndWait( SUPPORTDIR ^ "dotnetfx.exe" , "/q:a/l" ,WAIT) < 0) then   
  236.           SprintfBox(MB_OK,".NET安装","安装.net框架时发生意外,请重新安装!");  
  237. else   
  238.     SprintfBox(MB_OK,".NET安装",".NET FrameWork 2.0已安装!");  
  239.     endif;  
  240. endif;              
  241. //----------------------------------------------------------------------   
  242. SetSqlServer:  
  243. //判断是否安装了SQL Server        
  244. RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE );  
  245. if ( RegDBSetKeyValueEx ("SOFTWARE//Microsoft//Microsoft SQL Server//80//MSSQLLicenseInfo//MSSQL8.00//DisplayName","DisplayName",REGDB_STRING,"SQL Server 2000",-1 ) < 0) then  
  246. SprintfBox(MB_OK,"SQL Server 2000 安装","尚未安装SQL Server 2000 !/n请点击“确定”以继续安装!");         
  247. if( LaunchAppAndWait( SUPPORTDIR ^ "SQL 2000 Enterprise//AUTORUN.EXE.exe" , "/q:a/l" ,WAIT) < 0) then   
  248.           SprintfBox(MB_OK,"SQL Server 2000 安装","安装SQL Server 2000 时发生意外,请重新安装!");  
  249. else   
  250.      SprintfBox(MB_OK,"SQL Server 2000 安装","SQL Server 2000 已安装!");  
  251.      endif;  
  252. endif;     
  253.   //------------------------------------------------------------------      
  254.   
  255. Dlg_SdWelcome:    //欢迎 对话框      
  256.     szTitle = "欢迎使用YHK_GF安装软件";  
  257.     szMsg = "YHK_GF安装软件将在您的计算机中安装/b/n/b/n“网上阅卷系统”,/b/n/b/n若要继续,请单击“下一步”。";   
  258.     nResult = SdWelcome(szTitle, szMsg);  
  259.     if (nResult = BACK) goto Dlg_SdWelcome;  
  260.       
  261. Dlg_SdLicense2: //软件许可协议  
  262.     szTitle ="欢迎您/b/n请仔细阅读用户协议,本协议具有法律效力!!";  
  263.     szOpt1 = "同意(&A)";  
  264.     szOpt2 = "不同意(&D)";  
  265.     //{{IS_SCRIPT_TAG(License_File_Path)  
  266.     szLicenseFile = SUPPORTDIR ^ "用户使用协议.rtf";  
  267.     //}}IS_SCRIPT_TAG(License_File_Path)  
  268.     //{{IS_SCRIPT_TAG(Dlg_SdLicense2)  
  269.     nResult = SdLicense2Rtf( szTitle, szOpt1, szOpt2, szLicenseFile, bLicenseAccepted );  
  270.     //}}IS_SCRIPT_TAG(Dlg_SdLicense2)  
  271.     if (nResult = BACK) then  
  272.         goto Dlg_SdWelcome;  
  273.     else  
  274.         bLicenseAccepted = TRUE;  
  275.     endif;  
  276.       
  277.   
  278. Dlg_SdCustomerInformation:  
  279.   //用户信息对话框  
  280.     szMsg = "请您填写用户信息卡";  
  281.     szTitle = "欢迎您/b/n使用YHK安装系统";      
  282.     svName    = "";  
  283.     svCompany = "";  
  284.     nResult = SdCustomerInformation(szTitle, svName, svCompany, nUser);  
  285.     if (nResult = BACK) goto Dlg_SdWelcome;  
  286.    
  287.    
  288. Dlg_SetupType: //安装类型对话框  
  289.     szTitle = "安装类型/b/n请选择安装类型";  
  290.     szMsg = "请选择安装";  
  291.     nResult = SetupType(szTitle, szMsg, "", nSetupType, 0);  
  292.     if (nResult = BACK) then  
  293.         goto Dlg_SdCustomerInformation;  
  294.     else  
  295.         nSetupType = nResult;  
  296.         if (nSetupType != CUSTOM) then  
  297.             nvSize = 0;  
  298.             FeatureCompareSizeRequired(MEDIA, INSTALLDIR, nvSize);  
  299.             if (nvSize != 0) then        
  300.                 MessageBox(szSdStr_NotEnoughSpace, WARNING);  
  301.                 goto Dlg_SetupType;  
  302.             endif;  
  303.             bCustom = FALSE;  
  304.             goto Dlg_SQL;  
  305.         else  
  306.             bCustom = TRUE;  
  307.         endif;  
  308.     endif;      
  309.   
  310. Dlg_SdAskDestPath:     
  311.     szTitle="";  
  312.     szMsg="";     
  313.     nResult = SdAskDestPath(szTitle, szMsg, INSTALLDIR, 0);  
  314.     if (nResult = BACK) goto Dlg_SetupType;  
  315.   
  316. Dlg_SdFeatureTree:   
  317.     szTitle    = "";  
  318.     szMsg      = "";  
  319.     if (nSetupType = CUSTOM) then  
  320.         nResult = SdFeatureTree(szTitle, szMsg, INSTALLDIR, "", 2);  
  321.         if (nResult = BACK) goto Dlg_SdAskDestPath;   
  322.     endif;  
  323.   
  324. Dlg_SQL:  
  325.     nResult = OnSQLLogin( nResult );  
  326.     if( nResult = BACK ) then  
  327.         if (!bCustom) then  
  328.             goto Dlg_SetupType;      
  329.         else  
  330.             goto Dlg_SdFeatureTree;  
  331.         endif;  
  332.     endif;  
  333.   
  334. Dlg_SdStartCopy:   //准备就绪对话框   
  335.     szTitle = "可以安装“网上阅卷系统”了/b/n安装准备工作已就绪,可以开始安装了。";  
  336.     szMsg ="";// "单击“安装”以开始安装。/b/n如果要检查或更改任何安装设置,请单击“上一步”。单击“取消”退出安装向导。";  
  337.   
  338.     listStartCopy = ListCreate( STRINGLIST );  
  339.     //The following is an example of how to add a string(svName) to a list(listStartCopy).  
  340.     //eg. ListAddString(listStartCopy,svName,AFTER);   
  341.     ListAddString(listStartCopy,"你的选择如下:",AFTER);  
  342.     ListAddString(listStartCopy,"",AFTER);   
  343.     ListAddString(listStartCopy,"安装路径:"+TARGETDIR,AFTER);  
  344.     ListAddString(listStartCopy,"",AFTER);   
  345.     ListAddString(listStartCopy,"程序组名:"+SHELL_OBJECT_FOLDER,AFTER);  
  346.     ListAddString(listStartCopy,"",AFTER);   
  347.     if (nSetupType = CUSTOM) then  
  348.         ListAddString(listStartCopy,"安装类型:"+"自定义",AFTER);   
  349.     elseif (nSetupType = TYPICAL) then  
  350.         ListAddString(listStartCopy,"安装类型:"+"典型",AFTER);   
  351.     elseif (nSetupType = COMPACT) then  
  352.         ListAddString(listStartCopy,"安装类型:"+"压缩",AFTER);   
  353.     endif;  
  354.     nResult = SdStartCopy( szTitle, szMsg, listStartCopy );           
  355.     ListDestroy(listStartCopy);  
  356.     if (nResult = BACK) then  
  357.         goto Dlg_SQL;  
  358.     endif;  
  359.          //---------------------------------------------------------------------------------  
  360.      // 在桌面上添加快捷方式   
  361.     AddFolderIcon(FOLDER_DESKTOP,"网上阅卷系统首页","/"http://"+szIp+":8080/Default.aspx/"",TARGETDIR,TARGETDIR+"//TempIco//021.ico",0,"",REPLACE);     
  362.     //添加程序快捷方式  
  363.     AddFolderIcon(FOLDER_PROGRAMS^"网上阅卷系统GF安装","网上阅卷系统首页","/"http://"+szIp+":8080/Default.aspx/"",TARGETDIR,TARGETDIR+"//TempIco//021.ico",0,"",REPLACE);     
  364.     //添加卸载快捷方式  
  365.     AddFolderIcon(FOLDER_PROGRAMS^"网上阅卷系统GF安装","卸载","/""+PROGRAMFILES+"/InstallShield Installation Information//{E71A5501-0CCF-4765-A743-8F1352781170}//Setup.exe /"",TARGETDIR,TARGETDIR+"//TempIco//011.ico",0,"",REPLACE);     
  366.     // <PROGRAMFILES>/InstallShield   Installation   Information/{96C6BC6D-1EAA-43C2-9A2C-CB1242590FD7}/Setup.exe     
  367.     // 其中     
  368.     // {611b4a59-fae0-443b-acbb-8cb1ce57fada}     
  369.     // 这个值是这样取得的     
  370.     // Project-》Setting-》General-》Project对应的那项     
  371.   
  372. //---------------------------------------------------------------------------------------------------------------      
  373.   
  374.     // setup default status  
  375.     Enable(STATUSEX);  
  376.    
  377.     return 0;  
  378. end;  
  379. //---------------------------------------------------------------------------  
  380. // OnMaintUIAfter  
  381. //  
  382. // The OnMaintUIAfter event called by the framework after the file transfer  
  383. // of the setup when the setup is running in maintenance mode. By default  
  384. // this event displays UI that informs the end user that the maintenance setup  
  385. // has been completed successfully.  
  386. //事件的OnMaintUIAfter所呼吁的框架后,文件传输在安装时,安装程序在维护模式下运行。  
  387. //默认情况下 这一事件显示界面,通知最终用户,维修安装 已成功完成。...  
  388. //---------------------------------------------------------------------------  
  389. function OnMaintUIAfter()  
  390.     STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;  
  391.     NUMBER bOpt1, bOpt2;  
  392. begin  
  393.   
  394.     Disable(STATUSEX);  
  395.   
  396.     bOpt1   = FALSE;  
  397.     bOpt2   = FALSE;  
  398.       
  399.     // Added - Version 9.5 - Use appropriate strings for complete  
  400.     // uninstall.  
  401.     if( REMOVEALLMODE ) then  
  402.         szTitle = SdLoadString(IFX_SDFINISH_REMOVE_TITLE);  
  403.         szMsg1 = SdLoadString(IFX_SDFINISH_REMOVE_MSG1);   
  404.                 //卸载完成  
  405.         szTitle="卸载完毕";  
  406.         szMsg1="已完全卸载“网上阅卷系统”";   
  407.     else  
  408.         szTitle = SdLoadString(IFX_SDFINISH_MAINT_TITLE);      
  409.         szMsg1  = SdLoadString(IFX_SDFINISH_MAINT_MSG1);  
  410.     endif;  
  411.          szMsg2 ="谢谢您使用保定银河卡电子公司的产品。";  
  412.     SdFinishEx(szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2);  
  413. end;  
  414. //---------------------------------------------------------------------------  
  415. // OnFirstUIAfter  
  416. //  
  417. // The OnFirstUIAfter event called by the framework after the file transfer  
  418. // of the setup when the setup is running in first install mode. By default  
  419. // this event displays UI that informs the end user that the setup has been  
  420. // completed successfully.  
  421. //事件的OnFirstUIAfter后调用文件transferof安装时,安装程序在第一次安装模式下运行的框架。  
  422. //默认情况下此事件显示界面,通知最终用户,安装程序已成功完成。  
  423. //---------------------------------------------------------------------------  
  424. function OnFirstUIAfter()  
  425.     STRING szTitle, szMsg1, szMsg2, szOption1, szOption2;  
  426.     NUMBER bOpt1, bOpt2;   
  427.     string szBmpPath;//自定义  
  428. begin        
  429.         szBmpPath=SUPPORTDIR+"//left.bmp;1;0,0,0";     
  430.         //SizeWindow (METAFILE,50, 50);     
  431.         DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath,TRUE); // 设置左边的图片   
  432.         Disable(STATUSEX);  
  433.            //---------------------------------------  
  434.     //安装完成之时  
  435.     szTitle = "阅卷系统安装完毕";  
  436.     szMsg1 = "谢谢您使用YHK_GF安装程序!!";   
  437.     szMsg2 = "已成功安装网“网上阅卷系统”,请单击“完成”以退出安装向导。";  
  438.     bOpt1  = FALSE;  
  439.     bOpt2  = FALSE;  
  440.     szMsg1 = SdLoadString(IFX_SDFINISH_MSG1);  
  441.     SdFinishEx(szTitle, szMsg1, szMsg2, szOption1, szOption2, bOpt1, bOpt2);  
  442. end;  
  443. //---------------------------------------------------------------------------  
  444. // OnSQLLogin  
  445. //---------------------------------------------------------------------------  
  446. function number OnSQLLogin( nBtn )  
  447. string sMessage;  
  448. string szConnection,szDB, sTemp[MAX_PATH];  // szServer, szUser, szPassword,   
  449. number nResult, nSize, nCount;  
  450. BOOL   bNext;  //bWinLogin,   
  451. LIST   listConnections;      
  452. STRING svResult,svLine;//自定义      
  453. number nvFileHandle;      
  454. begin  
  455.   
  456.     //First initialize SQL Server runtime  
  457. //第一初始化的SQL Server运行  
  458.     SQLRTInitialize2();  
  459.   
  460.    // Suppress ISSQLSRV.DLL to show a connection error message.  
  461.    //禁止ISSQLSRV.DLL显示连接错误信息  
  462.     MsiSetProperty( ISMSI_HANDLE, "IS_SQLSERVER_CA_SILENT", "1" );  
  463.   
  464.     //Get the names of all the necessary connections  
  465.     listConnections = SQLRTGetConnections();  
  466.     ListGetFirstString (listConnections, szConnection);  
  467.   
  468.     nCount = 0;  
  469.   
  470.     //determine if NEXT or BACK will be returned   
  471.     //if there are no connections to make  
  472.     //确定下一个或返回将被退回  
  473.      //如果没有连接  
  474.     if( nBtn != BACK ) then  
  475.         bNext = TRUE;  
  476.     else  
  477.         bNext = FALSE;  
  478.         //start at end if going BACK  
  479.                 //退回  
  480.         while (ISERR_SUCCESS = ListGetNextString( listConnections, szConnection ) );  
  481.             nCount++;  
  482.         endwhile;  
  483.     endif;  
  484.   
  485.       
  486.     // Login for each connection  
  487.     //登录每个连接  
  488.     while (nResult = ISERR_SUCCESS)  
  489.   
  490.         //Get Default values for connection  
  491.         //获得连接字符串  
  492.         SQLRTGetConnectionInfo( szConnection, szServer, szDB, szUser, szPassword );  
  493.   
  494.         bWinLogin = SQLRTGetConnectionAuthentication( szConnection );  
  495.   
  496.         // Display login dialog (without connection name)  
  497.         //显示登录对话框没有连接名称  
  498.         // COMMENT OUT TO SWAP DIALOGS  
  499.         //注释外部全系统计划的对话  
  500.             nResult = SQLServerSelectLogin2( szConnection, szServer, szUser, szPassword, bWinLogin, szDB, FALSE, TRUE );  
  501.               //下面的是只显示 登录用户和密码的不显示数据库和windows登录选择  
  502.              //nResult = SQLServerLogin( "", szUser, szPassword );  
  503.         // Display login dialog (with connection name)  
  504.         //显示登录对话框没有连接名称  
  505.         // UNCOMMENT TO SWAP DIALOGS  
  506.         //注释外部全系统计划的对话  
  507.         // nResult = SQLServerSelectLogin2( szConnection, szServer, szUser, szPassword, bWinLogin, szDB, TRUE, TRUE );  
  508.   
  509.         if( nResult = NEXT ) then  
  510.   
  511.             //store data in case we need it again  
  512.             //保存数据库配置信息,以备下次需要  
  513.             SQLRTPutConnectionInfo2( szConnection, szServer, szDB, szUser, szPassword );  
  514.   
  515.             SQLRTPutConnectionAuthentication( szConnection, bWinLogin );  
  516.   
  517.             //test connection      
  518.             //测试连接  
  519.             nResult = SQLRTTestConnection2( szConnection, szServer, szDB, szUser, szPassword, bWinLogin );  
  520.   
  521.             nSize = MAX_PATH;  
  522.             MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_STATUS", sTemp, nSize );  
  523.   
  524.            if( sTemp != "0" ) then  
  525.   
  526.                 nSize = _MAX_PATH;  
  527.                 MsiGetProperty( ISMSI_HANDLE, "IS_SQLSERVER_STATUS_ERROR", sMessage, nSize );  
  528.                      
  529.                 if( nSize = 0 ) then  
  530.                     Sprintf(sMessage, SdLoadString( IDS_IFX_SQL_ERROR_LOGIN_FAILED ), szConnection, SdLoadString( ISCRIPT_E_UNKNOWN_ERROR_DESC ));  
  531.                 endif;  
  532.                   
  533.                 MessageBox( sMessage, MB_OK );  
  534.   
  535.                 //Show same login dialog again  
  536.                 //显示相同的数据库登录对话框  
  537.                 nResult = ListCurrentString(listConnections, szConnection);  
  538.   
  539.             else //SUCCESS  
  540.                  //成功  
  541.                 //继续下一个连接  
  542.                 //Move on to next connection  
  543.                 nCount++;  
  544.                 bNext = TRUE;  
  545.                 nResult = ListGetNextString(listConnections, szConnection);  
  546.               // MsiSetProperty  
  547.               //设置Property里的值  
  548. (ISMSI_HANDLE,"Connection_Property","server="+szServer+";database=wxd;uid="+szUser+";pwd="+szPassword);  
  549.   
  550.             endif;  
  551.   
  552.         else  
  553.   
  554.             //BACK  
  555.             //回退  
  556.             nCount--;  
  557.             bNext = FALSE;  
  558.             nResult = ListSetIndex( listConnections, nCount );  
  559.             ListCurrentString( listConnections, szConnection );  
  560.   
  561.         endif;  
  562.   
  563.     endwhile;  
  564.    
  565.     if( bNext ) then  
  566.         return NEXT;  
  567.     else  
  568.         return BACK;  
  569.     endif;  
  570.   
  571. end;        
  572. //---------------------------------------------------------------------------  
  573. // OnMaintUIBefore  
  574. //  
  575. // The OnMaintUIBefore event is called by the framework when the setup is  
  576. // running in maintenance mode. By default this event displays UI that  
  577. // allows the end user to add or remove features, repair currently  
  578. // installed features or uninstall the application.  
  579. //该事件被称为OnMaintUIBefore由框架时,安装程序 在维护模式下运行。  
  580. //默认情况下此事件显示界面, 允许最终用户添加或删除功能,目前维修 安装的功能或卸载应用程序。  
  581. //---------------------------------------------------------------------------  
  582. function OnMaintUIBefore()  
  583.     NUMBER nResult, nType;  
  584.     STRING szTitle, szMsg, svDir, svResult, szCaption;   
  585.         //自定义   
  586.     STRING  szBmpPath;     
  587. begin     
  588. SetTitle("欢迎您使用银河卡电子公司的软件",0, BACKGROUNDCAPTION );//设置标题  
  589.   
  590. //----------------------------------------------------------------     
  591. szBmpPath=SUPPORTDIR+"//left.bmp;1;0,0,0";  //图片有白色的背景,所以设置白色为透明色  “位图文件名;透明标志;<未用>;<未用>;透明色”标准位图为57×53  
  592. //SizeWindow (METAFILE,50, 50);     
  593. DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath,TRUE); // 设置左边的logo图片   
  594. //------------------------------------------------------------------     
  595.   
  596.     // TO DO: if you want to enable background, window title, and caption bar title     
  597.         //如果你要启用的背景,窗口标题,标题和标题栏                              
  598.     // SetTitle( @PRODUCT_NAME, 24, WHITE );                     
  599.     // SetTitle( @PRODUCT_NAME, 0, BACKGROUNDCAPTION );               
  600.     // SetColor(BACKGROUND,RGB (0, 128, 128));                    
  601.     // Enable( FULLWINDOWMODE );                          
  602.     // Enable( BACKGROUND );                              
  603.       
  604. Dlg_Start:  
  605.          
  606.          
  607.          //----------------------------------------------------------------      
  608. //此处为第二次是卸载  
  609.     svResult   =  SdLoadString(IFX_MAINTUI_MSG);     
  610.     szCaption   = SdLoadString(IFX_ONMAINTUI_CAPTION);   
  611.     svResult="是否要完全卸载“网上阅卷系统”?";   
  612.     szCaption="确认卸载";   
  613.     nResult   =   SprintfBox(MB_OKCANCEL,szCaption,"%s",svResult);     
  614.     if   (nResult   =   IDCANCEL)   then     
  615.         exit;     
  616.     elseif(nResult   =   IDOK)   then      
  617.         //   setup   default   status     
  618.         SetStatusWindow(0,   "");     
  619.         Enable(STATUSEX);     
  620.         StatusUpdate(ON,   100);      
  621.         //-->Remove   all   components   
  622.         ComponentRemoveAll();      
  623.         //-------------------------------------------------------------------------------------------  
  624.         //分离数据库EXEC sp_detach_db @dbname = '数据库名称'   
  625.         //Server=[IS_SQLSERVER_SERVER];User id=[IS_SQLSERVER_USERNAME];Pwd=[IS_SQLSERVER_PASSWORD];DataBase=wxd;Max Pool Size=200;Connect Timeout=300;Connection Lifetime=3;   
  626.         //DetachDB();  
  627.         //-----------------------------------------------------------------------------------------------------      
  628.          
  629.     //----------------------------------------------------------------------------  
  630.     DeleteDir(TARGETDIR,ALLCONTENTS);     
  631.     DeleteDir(TARGETDIR,ONLYDIR);   
  632.   
  633.     //---------------------------------------------------------------------  
  634.     endif;     
  635. return   0;     
  636. //------------------------------------------------------------  
  637.          
  638.          
  639.     // Added in Version 9.5 - Support for REMOVEONLY option.  
  640.     //新增的版本9.5 - 为REMOVEONLY选择支持  
  641.     if( !REMOVEONLY ) then  
  642.         // In standard mode show maintenance dialog  
  643.                 //在标准模式对话框显示维修  
  644.         Disable(BACKBUTTON);  
  645.         nType = SdWelcomeMaint(szTitle, szMsg, MODIFY);  
  646.         Enable(BACKBUTTON);  
  647.     else  
  648.         // Hide the initial progress dialog as otherwise the user can  
  649.         // click on it, and hide the MessageBox.  
  650.         //隐藏,否则用户的对话,可以初步进展点击它,并隐藏在MessageBox。  
  651.         Disable( DIALOGCACHE );  
  652.   
  653.         // In RemoveOnly mode, set to remove.  
  654.         //在RemoveOnly模式,设置删除  
  655.         nType = REMOVEALL;  
  656.     endif;  
  657.       
  658.     // Show Uninstall Confirmation Dialog  
  659.         //显示卸载确认对话框  
  660.     if ( nType = REMOVEALL ) then  
  661.         nResult = MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO );  
  662.         if (nResult != IDYES ) then  
  663.               
  664.             if( REMOVEONLY ) then  
  665.                 // In REMOVEONLY mode, abort the setup.  
  666.                 //显示卸载确认对话框  
  667.                 abort;  
  668.             else  
  669.                 // In non-REMOVEONLY mode, redisplay the previous dialog.  
  670.                 //在非REMOVEONLY模式,重新显示以前的对话。  
  671.                 goto Dlg_Start;  
  672.             endif;  
  673.   
  674.         endif;  
  675.     endif;  
  676.   
  677.     nResult = NEXT;  
  678.   
  679. Dlg_SdFeatureTree:  
  680.     if (nType = MODIFY) then  
  681.         szTitle = "";  
  682.         szMsg = "";  
  683.         nResult = SdFeatureTree(szTitle, szMsg, INSTALLDIR, "", 2);  
  684.         if (nResult = BACK) goto Dlg_Start;  
  685.     endif;  
  686.   
  687.     switch(nType)  
  688.         case REMOVEALL: FeatureRemoveAll();  
  689.         case REPAIR:    FeatureReinstall();  
  690.     endswitch;  
  691.       
  692.     // setup default status   
  693.         //设置默认状态  
  694.     SetStatusWindow(0, "");  
  695.     Enable(STATUSEX);  
  696.     StatusUpdate(ON, 100);  
  697. end;  
  698. //---------------------------------------------------------------------------  
  699. // OnUninstall  
  700. //  
  701. // The OnUninstall event is called when the setup is run with the -uninst  
  702. // switch, in this case this is the only event that will be called.  
  703. //该OnUninstall活动名为安装程序时,使用- uninst运行开关,在这种情况下,这是唯一的事件,将被调用。  
  704. //---------------------------------------------------------------------------  
  705. function OnUninstall()  
  706.     BOOL   bvOpt1, bvOpt2;  
  707.     string szTitle, szMsg1, szMsg2, szOpt1, szOpt2, svResult, szCaption;  
  708. begin         
  709. //标题设置  
  710. SetTitle("欢迎您使用银河卡电子产品",   24,   WHITE);                                                                                    
  711.   
  712.     //-------------------------------------------------------   
  713.     // 在桌面上删除快捷方式   
  714.     DeleteFolderIcon (FOLDER_DESKTOP, TARGETDIR+"//TempIco//021.ico");   
  715.     //删除程序中的快捷方式  
  716.     DeleteFolderIcon(FOLDER_PROGRAMS^"网上阅卷系统GF安装",TARGETDIR+"//TempIco//011.ico");  
  717.     //------------------  
  718.     svResult = SdLoadString(ISWI_IS5_UNINST_MSG);  
  719.     szCaption = SdLoadString(IFX_ONMAINTUI_CAPTION);  
  720.     Sprintf (svResult, svResult, @PRODUCT_NAME);  
  721.     if (IDCANCEL = SprintfBox(MB_OKCANCEL, szCaption, svResult)) then  
  722.         abort;   
  723.     endif;  
  724.       
  725.     Enable(STATUSEX);  
  726.   
  727.     //////////////////////////////////////  
  728.     //DO NOT DELETE.  The below code will  
  729.     //initiate the uninstallation process.  
  730.     ComponentRemoveAll();  
  731.     ComponentTransferData(MEDIA);  
  732.     //////////////////////////////////////  
  733.       
  734.     Disable(STATUSEX);  
  735.   
  736.     bvOpt1 = FALSE;  
  737.     bvOpt2 = FALSE;  
  738.     szMsg1 = SdLoadString(IFX_SDFINISH_MAINT_MSG1);  
  739.     szTitle = SdLoadString(IFX_SDFINISH_MAINT_TITLE);  
  740.     SdFinishEx(szTitle, szMsg1, szMsg2, szOpt1, szOpt2, bvOpt1, bvOpt2);  
  741.     //删除安装文件  
  742.     DeleteDir(ProgramFilesFolder+"//InstallShield Installation Information//{E71A5501-0CCF-4765-A743-8F1352781170}",ALLCONTENTS);  
  743.     DeleteDir(ProgramFilesFolder+"//InstallShield Installation Information//{E71A5501-0CCF-4765-A743-8F1352781170}",ONLYDIR);     
  744.       
  745. end;     
  746.   
  747.   
  748. ///////////////////////////////////////////////////////////////////////  
  749. prototype AttachDB(STRING,STRING,STRING);  
  750. function number AttachDB(svSQLsvr,svSQLusr,svSQLpwd)   
  751.     STRING szCmdLine,szWaitTxt;   
  752. begin   
  753.     szWaitTxt=" 正在附加所需数据库……";   
  754.     SdShowMsg (szWaitTxt, TRUE);   
  755.     Delay(2);     
  756.     if(bWinLogin) then  
  757.     szCmdLine = " /E  /S "+svSQLsvr+" /Q /"EXEC  sp_attach_db  @dbname  =  N'YCSCMDB',@filename1  = N'"+ProgramFilesFolder^@COMPANY_NAME+"//示例数据库//YCSCMDB_Data.MDF',@filename2  = N'"+ProgramFilesFolder^@COMPANY_NAME+"//示例数据库//YCSCMDB_Log.LDF'/"";     
  758.     WriteDBInfo(" /E  /S "+svSQLsvr);  
  759.     else  
  760.     szCmdLine = " /U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q /"EXEC  sp_attach_db  @dbname  =  N'YCSCMDB',@filename1  = N'"+ProgramFilesFolder^@COMPANY_NAME+"//示例数据库//YCSCMDB_Data.MDF',@filename2  = N'"+ProgramFilesFolder^@COMPANY_NAME+"//示例数据库//YCSCMDB_Log.LDF'/"";   
  761.     WriteDBInfo(" /U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr);  
  762.     endif;   
  763.     //szCmdLine = "/U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q /"EXEC  sp_attach_db  @dbname  =  N'dlbj',@filename1  = N'"+TARGETDIR ^"dlbj_web.MDF',@filename2  = N'"+TARGETDIR ^"dlbmydb_log.LDF'/"";   
  764.       
  765.     if (LaunchAppAndWait("osql.exe", szCmdLine,WAIT) < 0) then   
  766.     MessageBox ("数据库附加失败!数据库文件已安装到本地目录,请手动附加!",SEVERE);   
  767.     endif;   
  768.     SdShowMsg (szWaitTxt, FALSE);   
  769.     //szWaitTxt=" 正在优化系统数据库……";   
  770.     //SdShowMsg (szWaitTxt, TRUE);   
  771.     //Delay(2);   
  772.     //szCmdLine = "/U "+svSQLusr+" /P "+svSQLpwd+" /S "+svSQLsvr+" /Q /"use dlbj ; exec sp_updatestats/"";   
  773. //  if (LaunchAppAndWait("osql.exe", szCmdLine,WAIT) < 0) then   
  774. //  MessageBox ("数据库优化失败!您可以在 sql查询分析器中执行 use dlbj ; exec sp_updatestats 完成!",SEVERE);   
  775. //  endif;   
  776. //  SdShowMsg (szWaitTxt, FALSE);   
  777.       
  778.     return 0;   
  779.   
  780. end;   
  781. //---------------------------------------------------------------------------  
  782. // OnEnd  
  783. //  
  784. // The OnEnd event is called at the end of the setup. This event is not  
  785. // called if the setup is aborted.  
  786. //---------------------------------------------------------------------------  
  787. function OnEnd()  
  788. begin   
  789.   
  790. end;  
  791. //---------------------------------------------------------------------------  
  792. // OnAppSearch  
  793. //  
  794. // The OnAppSearch event is called after OnBegin and can be used to search  
  795. // for previous versions of the current application. This event is called  
  796. // only when the setup is running in first install mode.  
  797. //---------------------------------------------------------------------------  
  798. function OnAppSearch()  
  799. begin  
  800. end;  
  801. //---------------------------------------------------------------------------  
  802. // OnBegin  
  803. //  
  804. // The OnBegin event is called directly by the framework after the setup  
  805. // initializes.  
  806. //---------------------------------------------------------------------------  
  807. function OnBegin()  
  808. begin  
  809.     // TO DO: you may change default non-UI setting, for example  
  810.     //  
  811.     // You may also perform your custom initialization steps, check requirements, etc.  
  812. end;  
  813. //---------------------------------------------------------------------------  
  814. // OnMoving  
  815. //  
  816. // The OnMoving event is called just after the standard MSI action   
  817. // 'InstallInitialize' is executed.  
  818. //---------------------------------------------------------------------------  
  819. function OnMoving()  
  820. begin  
  821. end;  

  822.   

  823. #include "featureevents.rul"  
复制代码


2、FeatureEvents.rul
  1. //---------------------------------------------------------------------------  
  2. // The Installed event is sent after the feature WebSite  
  3. // is installed.  
  4. //---------------------------------------------------------------------------  
  5.    
  6. export prototype WebSite_Installed();  
  7. function WebSite_Installed()  
  8. begin      
  9. //------------------------------------------------------------------------  
  10. //附加数据库  
  11. if !MAINTENANCE then  
  12.               //Server=[IS_SQLSERVER_SERVER];User id=[IS_SQLSERVER_USERNAME];Pwd=[IS_SQLSERVER_PASSWORD];DataBase=wxd;Max Pool Size=200;Connect Timeout=300;Connection Lifetime=3;   
  13.     AttachDB( szServer, szUser, szPassword);   
  14.   endif;  
  15.    
  16.     //---------------------------------------------------------------------------  
  17. end;  
  18. //---------------------------------------------------------------------------  
  19. // The Installing event is sent after the feature WebSite  
  20. // is installed.  
  21. //---------------------------------------------------------------------------  
  22.    
  23. export prototype WebSite_Installing();  
  24. function WebSite_Installing()   
  25.   
  26. begin        
  27.    
  28.   
  29.   
  30. end;  
  31. //---------------------------------------------------------------------------  
  32. // The UnInstalling event is sent just before the feature   
  33. // ExampleDatabase is uninstalled.  
  34. //---------------------------------------------------------------------------  
  35.    
  36. export prototype ExampleDatabase_UnInstalling();  
  37. function ExampleDatabase_UnInstalling()  
  38. begin   
  39. //-------------------------------------------------------------------------------------------  
  40. //分离数据库EXEC sp_detach_db @dbname = '数据库名称'   
  41. //Server=[IS_SQLSERVER_SERVER];User id=[IS_SQLSERVER_USERNAME];Pwd=[IS_SQLSERVER_PASSWORD];DataBase=wxd;Max Pool Size=200;Connect Timeout=300;Connection Lifetime=3;   
  42. //DetachDB();  
  43. //-----------------------------------------------------------------------------------------------------      
  44. end;  
  45. //---------------------------------------------------------------------------  
  46. // The Installing event is sent after the feature ExampleDatabase  
  47. // is installed.  
  48. //---------------------------------------------------------------------------  
  49.    
  50. export prototype ExampleDatabase_Installing();  
  51. function ExampleDatabase_Installing()  
  52. begin   
  53.   
  54.   
  55. end;  
  56. //---------------------------------------------------------------------------  
  57. // The UnInstalled event is sent after the feature ExampleDatabase  
  58. // is uninstalled.  
  59. //---------------------------------------------------------------------------  
  60.    
  61. export prototype ExampleDatabase_UnInstalled();  
  62. function ExampleDatabase_UnInstalled()  
  63. begin     
  64.     DeleteDir(ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库",ALLCONTENTS);  
  65.     DeleteDir(ProgramFilesFolder+"//"+@COMPANY_NAME+"//示例数据库",ONLYDIR);     
  66. end;  
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-19 15:25 , Processed in 0.105583 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表