Esempio n. 1
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            string databaseServer = Context.Parameters["server"].ToString();
            string userName       = Context.Parameters["user"].ToString();
            string userPass       = Context.Parameters["pwd"].ToString();
            string targetdir      = Context.Parameters["targetdir"].ToString();
            string port           = Context.Parameters["port"].ToString();
            string websitename    = Context.Parameters["websitename"].ToString();

            NewWebSiteInfo siteinfo = new NewWebSiteInfo("", port, websitename, @targetdir);

            CreateNewWebSite(siteinfo);
            SetFileRole();
            //WriteToReg("WebSiteID");
            //if (this.Context.Parameters["deskcut"] == "1")    //创建桌面快捷方式
            //{
            //    CreateDeskTopCut();
            //}
            //if (this.Context.Parameters["pmenu"] == "1")    //创建应用程序菜单项
            //{
            //    CreateProCut();
            //}
            if (dataBaseType.Equals("SQL"))
            {
                ReWriteConfig();
                string connStr = string.Format("data source={0};user id={1};password={2};persist security info=false;packet size=4096", databaseServer, userName, userPass);
                string strSql  = "EXEC sp_attach_db  @dbname  =  N'" + dbName + "',"
                                 + "@filename1  =  N'" + targetdir + "DataBase\\GrgtInstrument.mdf',"
                                 + "@filename2  =  N'" + targetdir + "DataBase\\GrgtInstrument_Log.ldf'";
                ExecuteSql(connStr, "master", strSql);
            }
        }
Esempio n. 2
0
        public void CreateNewWebSite(NewWebSiteInfo siteInfo)
        {
            DirectoryEntry rootEntry = GetDirectoryEntry(entPath);

            string         newSiteNum   = GetNewWebSiteID();
            DirectoryEntry newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");

            newSiteEntry.CommitChanges();

            newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
            newSiteEntry.Properties["ServerComment"].Value  = siteInfo.NameOfWebSite;
            newSiteEntry.CommitChanges();
            DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");

            vdEntry.CommitChanges();
            string ChangWebPath = siteInfo.WebPath.Trim().Remove(siteInfo.WebPath.Trim().LastIndexOf('\\'), 1);

            vdEntry.Properties["Path"].Value = ChangWebPath;


            vdEntry.Invoke("AppCreate", true);                                 //创建应用程序

            vdEntry.Properties["AccessRead"][0]      = true;                   //设置读取权限
            vdEntry.Properties["AccessWrite"][0]     = true;
            vdEntry.Properties["AccessScript"][0]    = true;                   //执行权限
            vdEntry.Properties["AccessExecute"][0]   = false;
            vdEntry.Properties["AppFriendlyName"][0] = siteInfo.NameOfWebSite; //应用程序名称
            vdEntry.Properties["AuthFlags"][0]       = 1;                      //0表示不允许匿名访问,1表示可以匿名访问,3为基本身份验证,7为windows继承身份验证
            vdEntry.CommitChanges();

            #region 创建应用程序池
            string appPoolName = "GrgtInstrumentPool";
            if (!IsAppPoolName(appPoolName))
            {
                DirectoryEntry newpool;
                DirectoryEntry appPools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
                newpool = appPools.Children.Add(appPoolName, "IIsApplicationPool");
                newpool.CommitChanges();
            }
            #endregion

            #region 针对IIS7

            int Version = int.Parse(GetIISVerstion());
            if (Version > 6)
            {
                #region 修改应用程序的配置(包含托管模式及其NET运行版本)
                ServerManager sm = new ServerManager();
                sm.ApplicationPools[appPoolName].ManagedRuntimeVersion = "v4.0";
                sm.ApplicationPools[appPoolName].Enable32BitAppOnWin64 = true;
                sm.ApplicationPools[appPoolName].ManagedPipelineMode   = ManagedPipelineMode.Integrated; //托管模式:Integrated为集成 Classic为经典
                sm.CommitChanges();
                #endregion
            }
            vdEntry.Properties["AppPoolId"].Value = appPoolName;
            vdEntry.CommitChanges();
            #endregion

            #region 更新脚本映射 网站.net framwork版本 (2.0/4.0)
            //启动aspnet_regiis.exe程序
            string           fileName  = Environment.GetEnvironmentVariable("windir") + @"\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe";
            ProcessStartInfo startInfo = new ProcessStartInfo(fileName);
            //处理目录路径
            string path  = vdEntry.Path.ToUpper();
            int    index = path.IndexOf("W3SVC");
            path = path.Remove(0, index);
            //启动ASPnet_iis.exe程序,刷新脚本映射
            startInfo.Arguments              = "-i -enable ";
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            Process process = new Process();
            process.StartInfo = startInfo;
            process.Start();
            process.WaitForExit();
            string errors = process.StandardError.ReadToEnd();
            if (errors != string.Empty)
            {
                throw new Exception(errors);
            }
            #endregion
        }