用Inno Setup制作WEB程序安装包

简介: 原文 用Inno Setup制作WEB程序安装包 最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考看看inno 的脚本     [Setup] AppCopyright=test AppName=test AppVerName=test v2.

原文 用Inno Setup制作WEB程序安装包

最近做了一个WEB程序的安装包,我把制作的过程做个介绍,贴出源码给大家做个参考

看看inno 的脚本

   
[Setup]
AppCopyright=test
AppName=test
AppVerName=test v2.0
SolidCompression=true
OutputDir=Output\
OutputBaseFilename=test_setup
DefaultDirName={pf}\Lms
DefaultGroupName=Lms
;安装程序的基本信息
[_ISTool]
UseAbsolutePaths=false

[UninstallDelete]
Type: files; Name: {app}\init_test.log
Type: dirifempty; Name: {app}\database
;需要提示卸载程序额外删除的目录
[Run]
Filename: {tmp}\SetACL.EXE; Parameters: "-ot file -on ""{app}"" -actn ace -ace ""n:S-1-5-20;s:y;p:change,full"""; Flags: runhidden waituntilterminated skipifdoesntexist
Filename: {tmp}\SetACL.EXE; Parameters: "-ot file -on ""{app}"" -actn ace -ace ""n:S-1-5-32-545;s:y;p:change,full"""; Flags: runhidden waituntilterminated skipifdoesntexist
Filename: {tmp}\SetACL.EXE; Parameters: "-ot file -on ""{app}"" -actn ace -ace ""n:S-1-1-0;s:y;p:change,full"""; Flags: runhidden waituntilterminated skipifdoesntexist
Filename: {tmp}\SetACL.EXE; Parameters: "-ot file -on ""{app}\database"" -actn ace -ace ""n:S-1-1-0;s:y;p:change,full"""; Flags: runhidden waituntilterminated skipifdoesntexist
Filename: {tmp}\init_test.exe; Parameters: """{app}"" 2.0"; Description: Configure SQLServer; StatusMsg: Configuring Database; Flags: postinstall skipifdoesntexist
;uncomment this line to use for dotnet 1.1
;Filename: {tmp}\SetACL.exe; Parameters: "-ot file -on ""{win}\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files"" -actn ace -ace ""n:S-1-1-0;s:y;p:change,full"""; Flags: runhidden
Filename: {tmp}\SetACL.exe; Parameters: "-ot file -on ""{win}\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files"" -actn ace -ace ""n:S-1-1-0;s:y;p:change,full"""; Flags: runhidden
;安装过程需要运行的程序,SetACL.EXE是一个第三方组件使用方法大家可以google一下,init_test.exe为附加数据库和数据还有设置asp.net版本的程序

[Dirs]
Name: {app}\database
Name: {app}\course
;产生目录
[Types]
Name: Custom; Description: Custom installation; Flags: iscustom

[Files]
Source: 3rdParty\SetACL.exe; DestDir: {tmp}; flags: deleteafterinstall
Source: test\*; DestDir: {app}; Excludes:*.webinfo,*.vspscc, \obj,Thumbs.db,CVS,*.pdb,*.cs,*.scc,*.bak,*.csproj,*.log,*.Old,*.user,*.lic,*.sln,*.suo,8.rar; Flags: recursesubdirs
Source: test_table.sql; DestDir: {tmp}; Flags: deleteafterinstall
Source: test_Data.sql; DestDir: {tmp}; Flags: deleteafterinstall
Source: init_test.exe; DestDir: {tmp}; flags: deleteafterinstall
;需要随安装包一起打包的文件
[Code]
const
  VDirName = 'test';
  Vwebctrl = 'webctrl_client';
  IISServerNumber = '1';
  
function SafeCreateOleObject(ProgId:String;ExceptionMsg:String):Variant;
var
  retobj:Variant;
begin
  try
    retobj := CreateOleObject(ProgId);
  except
    RaiseException(ExceptionMsg+''#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
  end;
  Result:=retobj;
end;

{
   create virtual directory, pointing to installation directory
}

procedure SetupIIS;
var
  IIS, WebSite, WebServer, WebRoot, VDir: Variant;
begin
  { Create the main IIS COM Automation object }
  IIS:=SafeCreateOleObject('IISNamespace','Please install Microsoft IIS first.');
  { Connect to the IIS server }

  WebSite := IIS.GetObject('IIsWebService', GetComputerNameString() + '/w3svc');
  WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
  WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');

  { (Re)create a virtual dir }

  try
    WebRoot.Delete('IIsWebVirtualDir', VDirName);
  except
  end;
  try
    WebRoot.Delete('IIsWebVirtualDir', Vwebctrl);
  except
  end;

  If DirExists(ExpandConstant('{app}')) then
  begin
  VDir := WebRoot.Create('IIsWebVirtualDir', VDirName);
  VDir.AccessRead := True;
  VDir.AccessFlags:=529;
  VDir.AppFriendlyName := 'LMS Website';
  VDir.Path := ExpandConstant('{app}\');
  VDir.EnableDirBrowsing:=False;
  VDir.EnableDefaultDoc:=True;
  VDir.DefaultDoc :='Default.aspx';
  VDir.AppCreate(True);
  VDir.SetInfo();
  end;

  If DirExists(ExpandConstant('{app}\IEWebControl\'+Vwebctrl)) then
  begin
  VDir := WebRoot.Create('IIsWebVirtualDir', Vwebctrl);
  VDir.AccessRead := True;
  VDir.AccessFlags:=529;
  VDir.AppFriendlyName := 'visual web ctral';
  VDir.Path := ExpandConstant('{app}\IEWebControl\'+Vwebctrl);
  VDir.EnableDirBrowsing:=False;
  VDir.EnableDefaultDoc:=True;
  VDir.DefaultDoc :='default.htm';
  VDir.AppCreate(True);
  VDir.SetInfo();
  end;
end;
procedure ControlIIS(bState:boolean);
var
  resultcode:integer;
  param:string;
begin
      if bState then
         param:='START'
      else param:='STOP';

      Exec('NET.EXE',param+' "IIS ADMIN"',
              ExpandConstant('{sys}'),SW_SHOW,ewWaitUntilTerminated,resultcode
          );
end;
;在IIS默认站点下添加虚拟目录
procedure CurStepChanged(CurStep: TSetupStep);
begin
    case CurStep of
      ssPostInstall:
        begin
          SetupIIS();
          //ControlIIS(true);
        end;
      ssInstall:
        //ControlIIS(false);
    else
       ;
    end;
end;

  

再来看一下init_lms.exe的主要方法:

  
 private void CreateDatabase()
        {
            string sql = " CREATE DATABASE "
                               + dbName;
                              
            if (IsLocalInstall())
            {
                sql += " ON PRIMARY (NAME = " + dbDataName + ", "
                       + " FILENAME = '" + getDir("database\\" + dbDataName + ".mdf") + "', "
                               + " SIZE = 5MB,"
                               + " FILEGROWTH =1) "
                               + " LOG ON (NAME =" + dbLogName + ", "
                               + " FILENAME = '" + getDir("database\\" + dbLogName + ".ldf") + "', "
                               + " SIZE = 1MB, "
                               + " FILEGROWTH =1) ";
            }
            sql += " COLLATE Chinese_PRC_CI_AS";
            try
            {
                this.Cursor = Cursors.WaitCursor;
                frmProg.StepText("drop database");
                if (chkCreateDB.Checked)
                {
                    try
                    {
                        execSQL("master", "DROP DATABASE " + dbName);
                        writeLog("old database dropped");
                    }
                    catch (Exception)
                    {
                        writeLog("database not found or unable to be dropped");
                    }
 
                }
                frmProg.StepText("creating database");
                if (chkCreateDB.Checked)
                {                 
                    try
                    {
                        execSQL("master", sql);
                        writeLog("DB CREATED:" + sql);
                    }
                    catch (Exception e)
                    {
                        writeLog("DB CREATING ERROR:" + e.Message);
                    }
                }                
                
                frmProg.StepText("creating tables");
                
                if (chkTables.Checked)
                {
                    writeLog("exec lmsdb_table.sql");
                    dmoExecSQL(sqlb_t.ToString());//dbName, sqlb);
                }
                
                frmProg.StepText("initialize base data");
                
                if (chkDatas.Checked)
                {
                    //writeLog(sqlb.ToString());
                    writeLog("exec lmsbasedata.sql");
                    dmoExecSQL(sqlb_d.ToString());//execSQL(dbName, sqlb);
                }
                frmProg.StepText("database initialization is done");
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

  


这个方法主要是创建数据库文件

  
private void setAspNetVersion(string m,string i)
         {
             string dotnetdir=addBackSlash(Environment.GetEnvironmentVariable("windir"))+"Microsoft.Net";
             string[] dirs = Directory.GetDirectories(dotnetdir+"\\Framework\\");
             foreach (string d in dirs)
             {
                 int p = d.LastIndexOf("\\v");
                 if (p >= 0)
                 {
                     string v = d.Substring(p + 2);
                     aspver = v;
                     string[] mi = v.Split(new char[] { '.' });
                     if (mi[0].CompareTo(m)==0 && mi[1].CompareTo(i)>=0)
                     {                        
                         //found the directory
                         string regiis = d + "\\aspnet_regiis.exe";
                         if (File.Exists(regiis)){
                             Process proc=new Process();
                             try{
                                 proc.StartInfo.FileName=regiis;
                                 proc.StartInfo.Arguments = "-s W3SVC/1/ROOT/Lms";
                                 proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                                 proc.StartInfo.CreateNoWindow=true;
                                 proc.Start();
                                 proc.WaitForExit(10000);
                             }catch (Win32Exception e){
                                 
                                  if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                                 {
                                 Console.WriteLine(e.Message + ". Check the path.");
                                  } else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
                                 {
                                      Console.WriteLine(e.Message + 
                         ". You do not have permission to run.");
                                  }
                             }    //catch                                           
                         }//if file.exists
                     }//if compare version
                 }//if pos>=0
             }//for each
 
         }

  


这个方法主要是利用aspnet_regiis.exe来修改ASP.NET的版本,这个文件在Microsoft.Net目录下

目录
相关文章
|
3月前
|
Java 应用服务中间件 Apache
Maven程序 tomcat插件安装与web工程启动
Maven程序 tomcat插件安装与web工程启动
41 0
|
2月前
|
设计模式 前端开发 数据库
深入理解MVC设计模式:构建高效Web应用程序的基石
【7月更文挑战第4天】在软件工程领域,设计模式是解决常见问题的一系列经过验证的方法。其中,Model-View-Controller(MVC)设计模式自诞生以来,便成为了构建用户界面,特别是Web应用程序的黄金标准。MVC通过将应用程序逻辑分离为三个核心组件,提高了代码的可维护性、可扩展性和重用性。本文将深入探讨MVC设计模式的原理,并通过一个简单的代码示例展示其应用。
65 0
|
3月前
|
分布式计算 并行计算 安全
在Python Web开发中,Python的全局解释器锁(Global Interpreter Lock,简称GIL)是一个核心概念,它直接影响了Python程序在多线程环境下的执行效率和性能表现
【6月更文挑战第30天】Python的GIL是CPython中的全局锁,限制了多线程并行执行,尤其是在多核CPU上。GIL确保同一时间仅有一个线程执行Python字节码,导致CPU密集型任务时多线程无法充分利用多核,反而可能因上下文切换降低性能。然而,I/O密集型任务仍能受益于线程交替执行。为利用多核,开发者常选择多进程、异步IO或使用不受GIL限制的Python实现。在Web开发中,理解GIL对于优化并发性能至关重要。
52 0
|
15天前
|
开发框架 前端开发 JavaScript
Web应用程序
Web应用程序
23 1
|
24天前
|
Python
【Azure 应用服务】如何为Web Jobs 安装Python包呢?
【Azure 应用服务】如何为Web Jobs 安装Python包呢?
【Azure 应用服务】如何为Web Jobs 安装Python包呢?
|
1月前
|
缓存 安全 网络协议
Web应用程序的DDoS攻击防护技术详解
【8月更文挑战第2天】DDoS攻击对Web应用程序的稳定性和可用性构成严重威胁。然而,通过综合运用上述防护技术,可以构建一个多层次、立体化的DDoS防御体系,有效应对各类攻击,最大限度地保障服务的连续性和可用性。网站程序开发人员和安全人员应密切关注最新的安全技术和趋势,不断优化和调整防护措施,确保Web应用程序的安全稳定运行。
|
1月前
|
移动开发 开发框架 小程序
开发H5程序或者小程序的时候,后端Web API项目在IISExpress调试中使用IP地址,便于开发调试
开发H5程序或者小程序的时候,后端Web API项目在IISExpress调试中使用IP地址,便于开发调试
|
26天前
|
Linux 网络安全 容器
【Azure App Service for Linux】Linux Web App如何安装系统未安装的包
【Azure App Service for Linux】Linux Web App如何安装系统未安装的包
|
28天前
|
SQL 监控 安全
|
2月前
|
存储 监控 安全
如何构建安全的Web应用程序:全方位指南
【7月更文挑战第28天】构建安全的Web应用程序是一个持续的过程,需要贯穿于整个应用程序的生命周期中。通过规划阶段的安全设计、开发阶段的安全措施实施、测试阶段的漏洞发现与修复以及部署与运维阶段的持续监控与维护,可以显著提高Web应用程序的安全性。希望本文的全方位指南能够为您在构建安全的Web应用程序方面提供有益的参考。