乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      網(wǎng)站安裝打包

       悟靜 2012-04-19

      怎么制作一個網(wǎng)站安裝的軟件?

      以前一開始的時候,是通過制作web安裝程序,然后框的一下把網(wǎng)站安裝完了。但是由于網(wǎng)站涉及到虛擬目錄,創(chuàng)建網(wǎng)站等操作,直接制作web安裝程序,如果中間有大量的配置是是靈活改變的,就變的相當?shù)臒╂i了。于是,換了一種方法:

      通過制作一個網(wǎng)站安裝的工具,然后通過制作應用程序安裝程序:

      --------就是制作一個網(wǎng)站安裝工具,然后通過安裝工具,再進行網(wǎng)站安裝?。?!

      一.工具的組成:五個部分介紹:

      1.軟件環(huán)境檢測

      2.webconfig修改

      3.新建網(wǎng)站(文件解壓->創(chuàng)建網(wǎng)站->瀏覽網(wǎng)站)

      4.IIS附加功能(查看站點、開啟站點,停止站點、重啟IIS、停止IIS、啟動IIS)

      5.工具App.config配置修改

       


      二.工具的打包,制作應用程序安裝程序。

      1.打包環(huán)境軟件(可選)

      2.打包IIS軟件(可選)

      3.壓縮站點

      4.創(chuàng)建程序菜單和桌面菜單

      這一節(jié)主要說安裝!

      1。操作系統(tǒng)

      這個應該不用了,沒系統(tǒng)也沒法運行了!

      2。IIS安裝

      這個是重點,最后面介紹!

      3。framework安裝

      這個也不用了,工具安裝時會先檢測,如果沒安裝這工具也打不開了!

      4。RAR安裝

      這個可以通過調(diào)用RAR的安裝文件啟動安裝。

      代碼簡單的就一句話:Process.Start(“RAR的安裝軟件路徑”);

       

       


      以下重點介紹IIS的自動安裝

       

      IIS的自動安裝也很簡單,先說下原理,再說下步驟:

      原理:通過調(diào)用Sysocmgr.exe系統(tǒng)自帶的工具安裝,主要參數(shù)為:"/i:sysoc.inf /u:\"這里是iis.txt文件路徑\""

      這里的參數(shù)沒有iis安裝文件的路徑,那路徑是在哪里指定的?答:路徑就在注冊表里指定了

      注冊表路徑為:Machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup

      這下面有兩個鍵:SourcePath和ServicePackSourcePath即為路徑

      所以,運行Sysocmgr.exe之前,

      一.是要先配置好iis.txt文件,

      二.是要先改注冊表路徑。

      三.是運行Sysocmgr.exe

      四.是把注冊表改回去

       

      主要步驟如下:

      一:新建一個txt文件,把IIS要裝的組件,按如下格式編寫:

      [Components]
      iis_common = ON
      iis_www = ON
      iis_asp = ON
      iis_inetmgr = ON
      aspnet= ON

      ----------------保存成iis.txt即可。里面的組件其它組件名稱,可以通過查看iis6.0的幫助文檔找到!

      二、三、四步,直接給出代碼出下:

       

      IIS安裝

                
      /// <summary>
                
      /// 安裝IIS
                
      /// </summary>

                
      /// <param name="installPath">iis386文件夾路徑</param>
                
      /// <param name="iisTxt">即存放安裝組件的文本路徑</param>
                
      /// <param name="errMsg">返回的錯誤信息</param>
                
      /// <returns></returns>
                public static bool Install(string installPath, string iisTxt,out string errMsg)
                {
                    errMsg 
      = ""
      ;
                    RegistryKey key 
      = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Setup",true
      );
                    
      if (key == null) { return false
      ; }
                    
      string sourcePath = Convert.ToString(key.GetValue("SourcePath"
      ));
                    
      string servicePackSourcePath = Convert.ToString(key.GetValue("ServicePackSourcePath"
      ));

                    
      try

                    {

                        key.SetValue(
      "ServicePackSourcePath", installPath);
                        key.SetValue(
      "SourcePath"
      , installPath);

                        Process rarPro 
      = new
       Process();
                        rarPro.StartInfo.FileName 
      = "Sysocmgr.exe"
      ;
                        rarPro.StartInfo.Arguments 
      = string.Format("/i:sysoc.inf /u:\"{0}\""
      , iisTxt);
                        rarPro.StartInfo.UseShellExecute 
      = false
      ;
                        rarPro.StartInfo.CreateNoWindow 
      = false
      ;
                        rarPro.StartInfo.WindowStyle 
      =
       ProcessWindowStyle.Hidden;
                        rarPro.Start();
      //開始  

                        rarPro.WaitForExit();//等待退出
                        rarPro.Dispose();
                        
      return true
      ;
                    }
                    
      catch (Exception err) { errMsg =
       err.Message; }
                    
      finally

                    {
                        key.SetValue(
      "ServicePackSourcePath", servicePackSourcePath);
                        key.SetValue(
      "SourcePath"
      , sourcePath);
                    }
                    
      return false
      ;
                }

      在net中,在System.Configuration.ConfigurationManager中,提供了幾個靜態(tài)方法,用來修改配置文件。

      如:System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMachineConfiguration();

      獲得應用程序下的配置文件,之后再用config進行操作。

      如果是在web中,那就是操作webconfig了!不過現(xiàn)在在winform中,就成了操作app.config了。

       


       

      于是,我選擇了還是以操作xml的方式來修改webconfig。

      這里寫了幾個類,主要也是模仿config的操作方式。代碼如下:

       

      代碼
      using System;
      using
       System.Collections.Generic;
      using
       System.Text;
      using
       System.Xml;
      namespace
       IISHelper
      {
          
      public class
       WebConfigHelper : IDisposable
          {
              
      private bool
       loadIsOK;
              
      /// <summary>

              
      /// 加載是否成功
              
      /// </summary>

              public bool LoadIsOK
              {
                  
      get { return
       loadIsOK; }
                  
      set { loadIsOK =
       value; }
              }

              
      private XmlDocument xDox = new
       XmlDocument();
              
      private string configPath = string
      .Empty;
              
      public WebConfigHelper(string
       webconfigPath)
              {
                  
      try

                  {
                      xDox.Load(webconfigPath);
                      configPath 
      = webconfigPath;
                      loadIsOK 
      = true
      ;
                  }
                  
      catch { loadIsOK = false
      ; }
                  
              }
              
      public
       WebConfigAppSetting AppSetting
              {
                  
      get

                  {
                      XmlNode xNode
      =xDox.SelectSingleNode("//configuration/appSettings");
                      
      if(xNode==null
      )
                      {
                          
      return null
      ;
                      }
                      
      return new WebConfigAppSetting(ref
       xNode);
                  }
              }
              
      public
       WebConfigConnectionStrings ConnectionStrings
              {
                  
      get

                  {
                      XmlNode xNode 
      = xDox.SelectSingleNode("//configuration/connectionStrings");
                      
      if (xNode == null
      )
                      {
                          
      return null
      ;
                      }
                      
      return new WebConfigConnectionStrings(ref
       xNode);
                  }
              }
              
      public bool
       Save()
              {
                  
      try

                  {
                      xDox.Save(configPath);
                      
      return true;
                  }
                  
      catch
       { }
                  
      return false
      ;
              }
              
      #region IDisposable 成員

              
      public void Dispose()
              {
                  xDox 
      = null
      ;
              }
              
      #endregion

          }
          
      public abstract class WebConfigBase
          {
              
      protected
       XmlNode node;
              
      public  void Add(string key, string
       value){}
              
      public abstract void Set(string key, string
       value);
              
      public abstract string Get(string
       key);
              
      public  void Remove(string key, string
       value){}
          }
          
      public class
       WebConfigAppSetting : WebConfigBase
          {
              
      internal  WebConfigAppSetting(ref
       XmlNode xNode)
              {
                  node 
      =
       xNode;
              }
              
      public override void Set(string key, string
       value)
              {
                  
      foreach (XmlNode addNode in
       node.ChildNodes)
                  {
                      
      if (addNode.Attributes != null && addNode.Attributes["key"].Value ==
       key)
                      {
                          addNode.Attributes[
      "value"].Value =
       value;
                          
      break
      ;
                      }
                  }
              }
              
      public override string Get(string
       key)
              {
                  
      foreach (XmlNode addNode in
       node.ChildNodes)
                  {
                      
      if (addNode.Attributes != null && addNode.Attributes["key"].Value ==
       key)
                      {
                        
      return  addNode.Attributes["value"
      ].Value;
                      }
                  }
                  
      return ""
      ;
              }
          }
          
      public class
       WebConfigConnectionStrings : WebConfigBase
          {
              
      internal  WebConfigConnectionStrings(ref
       XmlNode xNode)
              {
                  node 
      =
       xNode;
              }
              
      public override void Set(string key, string
       value)
              {
                  
      foreach (XmlNode addNode in
       node.ChildNodes)
                  {
                      
      if (addNode.Attributes != null && addNode.Attributes["name"].Value ==
       key)
                      {
                          addNode.Attributes[
      "connectionString"].Value =
       value;
                          
      break
      ;
                      }
                  }
              }
              
      public override string Get(string
       key)
              {
                  
      foreach (XmlNode addNode in
       node.ChildNodes)
                  {
                      
      if (addNode.Attributes != null && addNode.Attributes["name"].Value ==
       key)
                      {
                          
      return addNode.Attributes["connectionString"
      ].Value;
                      }
                  }
                  
      return ""
      ;
              }
          }
      }

       

       下面看一下界面的操作方法:

       

      界面操作方式
       WebConfigHelper allConfig = new WebConfigHelper(allConfigPath);
                  
      if (allConfig.LoadIsOK
      )
                  {
                      WebConfigAppSetting app 
      =
       allConfig.AppSetting;
                      
      if (app != null
      )
                      {
                        
        app.Set("MosFTPUserName"
      , txtMosFtpUserName.Text);
                          app.Set(
      "MosFTPPassword"
      , txtMosFtpPassword.Text);
                          app.Set(
      "ProvideFor"
      , cbbProvideFor.Text);
                       
      }
                      WebConfigConnectionStrings connString 
      =
       allConfig.ConnectionStrings;
                      
      if (connString != null
      )
                      {
                          connString.Set(
      "Conn", txtConn.Text);

                      }
                      allConfig.Save();
                      allConfig.Dispose();

                     
       MessageBox.Show("配置文件修改成功!");
                  }

       

       這里提示一下,web.config中,不要帶名稱空間,就是xmlns="xxxx一大堆的";

      在新建網(wǎng)站之前,就是要把打包好的項目拷貝一份到IIS指定的路徑上,同時,還要為個別目錄設置相應的訪問權限!

      于是就產(chǎn)生了兩件事:

      1。拷貝-》[這里我是采用RAR打包,然后解壓]

      2。設置權限

      如果是用拷貝方式,關于文件夾Copy,可以參考我的這篇文章:

      文件夾復制操作(非遞歸循環(huán)遍歷文件夾)

      http://www.cnblogs.com/cyq1162/archive/2007/05/28/762294.html

       


       

      為什么我沒采用拷貝的方法,前提有兩個,就是項目的文件夾有太多,在制作應用程序安裝程序時,只能添加文件,而文件夾只能一個一個的新建,太麻煩!要不就要把項目文件放到其它工程里,那通過項目主輸出來實現(xiàn)。我也不想放到新工程或集成到工具項目里,麻煩!

      于是,我通過壓縮項目文件,當然沒有壓縮web.config,因為web.config是要修改的,在壓縮包里就改不了。所以最后的做法是解壓RAR+文件拷貝web.config!

      關于RAR解壓,這里給出一段代碼就算解決了:

       

      RAR解壓
      public bool WARToFoler(string rarFromPath, string rarToPath)
              {
                  Process rarPro 
      = new
       Process();
                  rarPro.StartInfo.FileName 
      =
       AppConfig.SoftSetup_WinRARSystemPath;
                  rarPro.StartInfo.Arguments 
      = string.Format(" x  \"{0}\" \"{1}\" -o+ -r -ibck"
      , rarFromPath, rarToPath);
                  rarPro.StartInfo.UseShellExecute 
      = false
      ;
                  rarPro.StartInfo.RedirectStandardInput 
      = true
      ;
                  rarPro.StartInfo.RedirectStandardOutput 
      = true
      ;
                  rarPro.StartInfo.RedirectStandardError 
      = true
      ;
                  rarPro.StartInfo.CreateNoWindow 
      = true
      ;
                  rarPro.StartInfo.WindowStyle 
      =
       ProcessWindowStyle.Hidden;
                  rarPro.OutputDataReceived 
      += new
       System.Diagnostics.DataReceivedEventHandler(p_OutputDataReceived);
                  rarPro.ErrorDataReceived 
      += new
       DataReceivedEventHandler(rarPro_ErrorDataReceived);
                  rarPro.Start();
      //解壓開始  

                  rarPro.BeginOutputReadLine();
                  rarPro.BeginErrorReadLine();
                  rarPro.WaitForExit();
                  rarPro.Dispose();
                  
      return
       IsOK;
              }
              
      void rarPro_ErrorDataReceived(object
       sender, DataReceivedEventArgs e)
              {
                  
      if (e.Data!=null && e.Data != ""
      )
                  {
                      outMsg.Text 
      += "失敗:" + e.Data + "\r\n"
      ;
                      IsOK 
      = false
      ;
                  }
              }
              
      void p_OutputDataReceived(object
       sender, System.Diagnostics.DataReceivedEventArgs e)
              {
                  
      if (e.Data != null && e.Data != ""
      )
                  {
                      outMsg.Text
      +="成功:" + e.Data + "\r\n"
      ;
                  }
              }

       

      AppConfig.SoftSetup_WinRARSystemPath這個是就是安裝的RAR.exe路徑!

      -ibck參數(shù)是讓解壓在后臺運行,這樣可以不用彈出個解壓框!

      前些天也寫過一篇和RAR相關的文章:

      記錄下關于調(diào)用RAR解壓縮的問題

      http://www.cnblogs.com/cyq1162/archive/2010/01/13/1646678.html

      OK,RAR解壓就這么告一段落,接下來,我有一個App_Data目錄,由于會往里面寫生成的xml,所以為之添加一個可寫權限!


       

      設置權限的方式有三種,一種用net自帶的封裝類。另一種直接調(diào)用cacls.exe實現(xiàn),還有一種就是網(wǎng)上下的調(diào)用Microsoft.win32的某種復雜方式。

      以下就用第一種了。用net自帶的類實現(xiàn),非常的簡單,三行代碼:

       

      設置權限
      System.Security.AccessControl.DirectorySecurity fSec = new DirectorySecurity();
      fSec.AddAccessRule(
      new FileSystemAccessRule("everyone", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit |
       InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
      System.IO.Directory.SetAccessControl(path, fSec);

       

      這里是添加了一個everyone用戶,當然也可以換成aspnet用戶,具體看安全性要求給了!后面就給出了所有權限。

      具體關于權限的說明,多百google度或在vs下看按F1幫助文檔就清楚了!

      在IIS6.0的幫助文檔中,對于創(chuàng)建IIS,提供了三種程序管理方法,一種是WMI,另一種是ADSI,還有一種是命令行方法。

      這里,采用網(wǎng)上代碼比較多的ADSI編程方式進行。

       

       


       

      用C#進行ADSI編程,需要引用添加名稱空間:System.DirectoryServices

      主要操作類是:DirectoryEntry

      操作的內(nèi)容主要是xml節(jié)點:這點上,最好從IIS-》網(wǎng)站右鍵-》所有任務-》將配置保存到一個文件

      保存后,查看一下生成的xml內(nèi)容。看一下網(wǎng)站的節(jié)點是什么格式的,這對編程有點幫助。

      以下進入代碼階段

       

      創(chuàng)建網(wǎng)站
      DirectoryEntry iisEntry = new DirectoryEntry("IIS://localhost/w3svc");//獲得IIS節(jié)點
      //
      創(chuàng)建站點WebSiteID為整形,隨便生成,不重復即可,可能引發(fā)的問題,看我之前的一篇文章:
      //
      C# 創(chuàng)建網(wǎng)站 無法啟動與停止的問題
      //http://www.cnblogs.com/cyq1162/archive/2010/01/09/1642919.html

      DirectoryEntry site = (DirectoryEntry)iisEntry.Invoke("Create""IIsWebServer", WebSiteID);

      site.Invoke(
      "Put""ServerComment"
      , WebSiteName);
      site.Invoke(
      "Put""KeyType""IIsWebServer"
      );
      ArrayList serverBindings 
      = new
       ArrayList();
      serverBindings.Add(WebSiteIP 
      + ":" + WebSitePort + ":" +
       WebSiteDomain);
      if (WebSiteIP2 != "" && WebSitePort2 != ""
      )
      {
         serverBindings.Add(WebSiteIP2 
      + ":" + WebSitePort2 + ":" +
       WebSiteDomain);
      }
      site.Invoke(
      "Put""ServerBindings", serverBindings.ToArray());//這里是綁定多個IP

      site.Invoke("Put""ServerState"4);//4為停止,2為啟動
      site.Invoke("Put""FrontPageWeb"1);
      site.Invoke(
      "Put""DefaultDoc""index.html"
      );
      site.Invoke(
      "Put""ServerAutoStart"0
      );
      site.Invoke(
      "Put""AuthFlags"0
      );
      site.Invoke(
      "Put""ScriptMaps", ScriptArray().ToArray());//這里是一大堆2.0的腳本

      site.Invoke("Put""ServerSize"1);
      site.Invoke(
      "SetInfo"
      );

       

       

      創(chuàng)建完網(wǎng)站后,要創(chuàng)建默認根節(jié)點,代碼如下:

       

      創(chuàng)建根節(jié)點
      //創(chuàng)建默認根節(jié)點目錄
                          DirectoryEntry siteVDir = site.Children.Add("root""IISWebVirtualDir");
                          siteVDir.Properties[
      "AppIsolated"][0= 2
      ;
                          siteVDir.Properties[
      "Path"][0=
       WebSitePath;
                          siteVDir.Properties[
      "AccessFlags"][0= 513
      ;
                          siteVDir.Properties[
      "FrontPageWeb"][0= 1
      ;
                          siteVDir.Properties[
      "AppRoot"][0= string.Format("/LM/W3SVC/{0}/Root"
      , WebSiteID);
                          siteVDir.Properties[
      "AppFriendlyName"][0=
       WebSiteName;
                          siteVDir.Properties[
      "AuthFlags"][0= 0
      ;
                          siteVDir.Properties[
      "AccessScript"][0= true
      ;
                          siteVDir.Properties[
      "AccessSource"][0= true
      ;
                          siteVDir.Properties[
      "DirBrowseFlags"][0= 1073741886
      ;
                          siteVDir.Properties[
      "AuthNTLM"][0= true;//集成win身份驗證

                          siteVDir.Properties["AuthAnonymous"][0= true;//集成win身份驗證
                          siteVDir.Properties["UNCPassword"][0= "";
                          siteVDir.Properties[
      "DefaultDoc"][0=
       WebSiteDefaultDoc;
                       
                          siteVDir.CommitChanges();
                          site.CommitChanges();

       

       關于屬性及意思,除了可通過導出xml來查看之外,也可以看IIS幫助文檔下的“參考->配置數(shù)據(jù)庫參考屬性"進行進一步了解!

      打完,收工!

      接上一節(jié),網(wǎng)站安裝打包 新建網(wǎng)站[四][創(chuàng)建網(wǎng)站] 中

      這里提供一下創(chuàng)建虛擬目錄的大體方法,虛擬目錄是通過Root節(jié)點去創(chuàng)建的:

       

      創(chuàng)建虛擬目錄
      public bool CreateWebVirtualDir(string virtualName, string virtualPath, string siteID, out string msg)
              {
                  
      try

                  {
                      msg 
      = "";
                      siteID 
      = (string.IsNullOrEmpty(siteID) ?
       WebSiteID : siteID);
                      tempEntry.Path 
      = IISEntryPath + "/" + siteID + "/root";//這里是一個Root節(jié)點的DirectoryEntry

                      DirectoryEntry siteVDir = tempEntry.Children.Add(virtualName, "IISWebVirtualDir");
                      siteVDir.Invoke(
      "AppCreate"true
      );
                      siteVDir.Properties[
      "Path"][0=
       virtualPath;
                      siteVDir.Properties[
      "AccessFlags"][0= 513
      ;
                      siteVDir.Properties[
      "AppFriendlyName"][0=
       virtualName;
                      siteVDir.Properties[
      "AuthFlags"][0= 0
      ;
                      siteVDir.Properties[
      "AccessScript"][0= true
      ;
                      siteVDir.Properties[
      "AccessSource"][0= true
      ;
                      siteVDir.Properties[
      "AuthNTLM"][0= true;//集成win身份驗證

                      siteVDir.Properties["AuthAnonymous"][0= true;//集成win身份驗證
                      siteVDir.Properties["DefaultDoc"][0= WebSiteDefaultDoc;
                      siteVDir.Invoke(
      "AppCreate2"new object[1] { 2
       });
                      tempEntry.CommitChanges();
                      siteVDir.CommitChanges();
                      
      return true
      ;
                  }
                  
      catch
       (Exception err)
                  {
                      msg 
      =
       err.Message;
                  }
                  
      return false
      ;
              }

       下面再給出一些常用的方法:

      網(wǎng)站同名檢測:

       

      確認網(wǎng)站是否相同

              
      private bool CheckSiteExists(out string msg)
              {
                  msg 
      = ""
      ;
                  
      foreach (DirectoryEntry child in
       iisEntry.Children)
                  {
                      
      if (child.SchemaClassName == "IIsWebServer"
      )
                      {
                          
      if (child.Properties["ServerComment"].Value != null
      )
                          {
                              
      if (child.Properties["ServerComment"].Value.ToString().ToLower() ==
       WebSiteName.ToLower())
                              {
                                  msg 
      = "站點名稱已存在!"
      ;
                                  
      return true
      ;
                              }
                          }
                      }
                  }
                  
      return false
      ;
              }

       

       

       刪除一個站點:

       

      站點刪除
      public bool DeleteWebSiteByID(string siteID)
              {
                  
      try

                  {
                      siteID 
      = (string.IsNullOrEmpty(siteID) ? WebSiteID : siteID);
                      tempEntry.Path 
      = IISEntryPath + "/" +
       siteID;
                      iisEntry.Children.Remove(tempEntry);
                      iisEntry.CommitChanges();
                      
      return true
      ;
                  }
                  
      catch

                  {

                  }
                  
      return false;
              }

       

      Start和Stop網(wǎng)站:

       

      站點停止和啟動
      public bool StartWebSite(string siteID)
              {
                  
      try

                  {
                      siteID 
      = (string.IsNullOrEmpty(siteID) ? WebSiteID : siteID);
                      tempEntry.Path 
      = IISEntryPath + "/" +
       siteID;
                      tempEntry.Invoke(
      "Start"new object
      [] { });
                      
      return true
      ;
                  }
                  
      catch

                  { }
                  
      return false;
              }

              
      public bool StopWebSite(string
       siteID)
              {
                  
      try

                  {
                      siteID 
      = (string.IsNullOrEmpty(siteID) ? WebSiteID : siteID);
                      tempEntry.Path 
      = IISEntryPath + "/" +
       siteID;
                      tempEntry.Invoke(
      "Stop"new object
      [] { });
                      
      return true
      ;
                  }
                  
      catch
       { }
                  
      return false
      ;
              }

       

      在創(chuàng)建完網(wǎng)站與虛擬目錄,接下來就是要瀏覽網(wǎng)站了,于是,在界面上多加一個按鈕,點擊瀏覽是順勢而加了:

      代碼就一句:

       

      Process.Start("iexplore.exe"string.Format("http://{0}",txtWebsiteIP.Text));

       

       //IP地址用System.Net.Dns.GetHostAddresses(Dns.GetHostName())[0].ToString()就可獲取

       


      以下附加一下IIS一些其它功能:

       

      IIS重啟:

       

      IIS重啟
        public static bool ReStart(out string msg)
              {
                  
      try

                  {
                      msg 
      = "";
                      ServiceController iis 
      = new ServiceController("iisadmin"
      );
                      
      if (iis.Status ==
       ServiceControllerStatus.Running)
                      {
                          iis.Stop();
                      }
                      Process.Start(
      "iisreset");//重啟

                      iis.Dispose();
                      
      return true
      ;
                  }
                  
      catch
       (Exception err)
                  {
                      msg 
      =
       err.Message;
                  }
                  
      return false
      ;
              }

       

       IIS 開啟:

      IIS Start
       public static bool Start()
              {
                  ServiceController iis 
      = new ServiceController("iisadmin"
      );
                  
      if (iis.Status ==
       ServiceControllerStatus.Stopped)
                  {
                      iis.Start();
                  }
                  iis.Dispose();
                  
      return true
      ;
              }

       

      IIS 停止:

       

      IIS Stop
      public static bool Stop()
              {
                  ServiceController iis 
      = new ServiceController("iisadmin"
      );
                  
      if (iis.Status ==
       ServiceControllerStatus.Running)
                  {
                      iis.Stop();
                  }
                  iis.Dispose();
                  
      return true
      ;
              }

       

      注冊asp.net:

       

      aspnet 注冊
       string aspnet_regiisPath=@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe";
                  
      if (!
      System.IO.File.Exists(aspnet_regiisPath))
                  {
                      aspnet_regiisPath 
      = aspnet_regiisPath.Replace("C:""D:"
      );
                      
      if (!
      System.IO.File.Exists(aspnet_regiisPath))
                      {
                          aspnet_regiisPath 
      = aspnet_regiisPath.Replace("D:""E:"
      );
                          
      if (!
      System.IO.File.Exists(aspnet_regiisPath))
                          {
                              MessageBox.Show(
      "找不到Aspnet_regiis.exe的文件路徑!"
      );
                              
      return
      ;
                          }
                      }
                  }
                  Process.Start(aspnet_regiisPath, 
      "-i");

      在winform的安裝工具中,少不免有一些配置文件要放到app.config去,于是修改也是成了一種需求!

      無論是修改web.config還是app.config,普遍方式都有兩種,用net自帶封裝的類,或是自定義xml操作。

      可參考之前的一篇:網(wǎng)站安裝打包 webconfig修改[三]

      這里用的,還是以xml方式操作,比竟類都寫了,就順路用上了。

      這里的操作方式和webconfig的差不多一個樣:

       

      修改app.config
       string appConfigPath = startPath + "/XXX.exe.config";
                      WebConfigHelper appConfig 
      = new
       WebConfigHelper(appConfigPath);
                      
      if
       (appConfig.LoadIsOK)
                      {
                          WebConfigAppSetting appSetting 
      =
       appConfig.AppSetting;
                          
      if (appSetting != null
      )
                          {
                            
                              appSetting.Set(
      "SoftSetup_WinRARSystemPath"
      , txtSoftSetup_WinRARSystemPath.Text);
                              appSetting.Set(
      "SoftSetup_IISPath", txtSoftSetup_IISPath.Text.Replace(startPath, ""
      ));
                          }
                          
      if
       (appConfig.Save())
                          {
                              ConfigurationManager.RefreshSection(
      "appSettings"
      );
                              MessageBox.Show(
      "修改成功!"); return
      ;
                          }
                      }
                      MessageBox.Show(
      "修改失敗!");

       

       

      這里最值得一提的一句是:ConfigurationManager.RefreshSection("appSettings");

      修改完app.config時,雖然是修改了文件,但運行在內(nèi)存中的app.config卻還沒有修改.

      所以你改完文件,再取值,還是內(nèi)存中的舊值,因此修改完后,需要重新加載一下。

        本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多