使用Installshield制作asp,asp.net应用的安装程序

在使用asp,asp.net编写Web应用时,最大的烦恼莫过于程序的分发的部署,由于面向的最终用户,所以程序的安装的过程必须要简单,方便和快捷。
下面提供了Installshield的脚本,改脚本功能包括:
1,检测IIS是否安装
2,检测IE版本
3,自动建立SQL数据库
4,自动建立IIS虚拟目录
5,能读取注册表和INI文件
6,注册.dll组件
  应用程序开发环境:Windows2000+VS 2003+SQL2000
  制作安装程序环境:Installshield7.0(其实6.22以上都可以,只是中文语言包太难找,所以就用7.0了,另7.0界面也好看多了,XP风格)

////////////////////////////////////////////////////////////////////////////////
//                                                                           
//  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);//附加数据库
 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 ://设置数据库服务器 对话框
szTitle = "是否安装.net框架";
szMsg = "是否要安装.net框架,如果已经安装了.net框架则不需要安装。";
szField1="我要安装.net框架。";
szField2="我已经安装了,不需要再安装。";
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//如果已经安装则跳过
    if(LaunchAppAndWait (SUPPORTDIR^"mdac_typ.exe","",WAIT)<0) then
        MessageBox ("安装微软数据访问组件是发生以外,请重新安装。",SEVERE);
    goto  Dlg_SelMode;
    endif;
    endif;
   if(LaunchAppAndWait ( SUPPORTDIR ^"dotnetfx.exe " , "" ,WAIT)<0) then
    MessageBox ("安装.net框架时发生意外,请重新安装。",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 ://设置数据库服务器 对话框
szTitle = "设置IIS信息服务及数据库服务器";
szMsg = "现在开始设置IIS系统";
szQuestion=" 请输入本服务器的主机名或IP地址,安装程序将按照您提供的资料设置IIS信息服务。如果您没有填写,安装程序将自动跳过站点的创建!";
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 ://设置数据库服务器 对话框
szTitle = "设置数据库";
szMsg = "现在开始设置数据库系统";
szQuestion=" 请输入数据库服务器的用户名和密码,安装程序将按照您上步提供的IP地址和下面的用户名和密码创建和优化数据库系统。如果您提供的用户名和密码是错误的,安装程序将自动跳过数据的设置!";
//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  = "由于安装时发生意外导致安装失败";
    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,"请确认您填写的信息,按下一步开始复制文件",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); // 创建和 优化数据库
          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;


//////////////////////////
// 创建和优化数据库
//////////////////////////
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=" 正在创建数据库....";
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 ("数据库创建失败!请确您的系统中已安装 Microsoft SQL Server 2000.\n如仍无法解决,请联系系统供应商!",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 ("配置数据库失败!请尝试手动配置!",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="正在配置系统文件,请稍侯....";

  iniFile =SUPPORTDIR^"dbconn.ini";
   //SdShowMsg (szWaitTxt, TRUE);
    // Delay(2);
  if (GetSystemInfo (DATE, nvResult, svResult) < 0) then

      szInfo = "不能得到系统时间";

   else
     svDate=svResult+" ";
   endif;
   
    if (GetSystemInfo (TIME, nvResult, svResult) < 0) then

      szInfo = "不能得到系统时间";

   else
       svDate=svDate+svResult;
   endif;

 if (WriteProfString(iniFile,"dbconnection","server", svSQLsvr) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif; 
 
   if (WriteProfString(iniFile,"dbconnection","ip", svSQLsvr) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif;   
 
   if (WriteProfString(iniFile,"dbconnection","db_user",svSQLusr) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif;
 
    if (WriteProfString(iniFile,"dbconnection","db_pass",svSQLpwd) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif;
 
   if (WriteProfString(iniFile,"dbconnection","database", "fenoffice") <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif; 
       
     if (WriteProfString(iniFile,"webwork","webworkstart", svDate) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", SEVERE);
  endif; 
   if (WriteProfString(iniFile,"webwork","webworkpath", INSTALLDIR) <0) then
  MessageBox("dbconn.ini错误,系统将无法运行!", 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
//删除已经存在的虚拟目录
 // szCmdLine = SUPPORTDIR ^"adsutil.vbs delete w3svc/1/root/"^VirtualFolder;  
 // if(LaunchAppAndWait("CScript.exe", szCmdLine, WAIT)<0) then
 // MessageBox ("设置iis信息服务失败,请尝试手动配置!",INFORMATION);
 // endif;
//end;


//
//删除数据库
//
//
function DelDataBase(server,user,pass)
  STRING szWaitTxt,szdatabase1,szdatabase2,szdatabase3,path1;
begin

   
szWaitTxt=" 正在删除数据库....";
 
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;


http://blog.csdn.net/donkeyzheng/archive/2005/12/30/566301.aspx

你可能感兴趣的:(asp.net)