小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

網(wǎng)站安裝打包

 悟靜 2012-04-19

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

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

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

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

一.工具的組成:五個(gè)部分介紹:

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

2.webconfig修改

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

4.IIS附加功能(查看站點(diǎn)、開(kāi)啟站點(diǎn),停止站點(diǎn)、重啟IIS、停止IIS、啟動(dòng)IIS)

5.工具App.config配置修改

 


二.工具的打包,制作應(yīng)用程序安裝程序。

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

2.打包IIS軟件(可選)

3.壓縮站點(diǎn)

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

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

1。操作系統(tǒng)

這個(gè)應(yīng)該不用了,沒(méi)系統(tǒng)也沒(méi)法運(yùn)行了!

2。IIS安裝

這個(gè)是重點(diǎn),最后面介紹!

3。framework安裝

這個(gè)也不用了,工具安裝時(shí)會(huì)先檢測(cè),如果沒(méi)安裝這工具也打不開(kāi)了!

4。RAR安裝

這個(gè)可以通過(guò)調(diào)用RAR的安裝文件啟動(dòng)安裝。

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

 

 


以下重點(diǎn)介紹IIS的自動(dòng)安裝

 

IIS的自動(dòng)安裝也很簡(jiǎn)單,先說(shuō)下原理,再說(shuō)下步驟:

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

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

注冊(cè)表路徑為:Machine\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup

這下面有兩個(gè)鍵:SourcePath和ServicePackSourcePath即為路徑

所以,運(yùn)行Sysocmgr.exe之前,

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

二.是要先改注冊(cè)表路徑。

三.是運(yùn)行Sysocmgr.exe

四.是把注冊(cè)表改回去

 

主要步驟如下:

一:新建一個(gè)txt文件,把IIS要裝的組件,按如下格式編寫(xiě):

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

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

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

 

IIS安裝

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

          
/// <param name="installPath">iis386文件夾路徑</param>
          
/// <param name="iisTxt">即存放安裝組件的文本路徑</param>
          
/// <param name="errMsg">返回的錯(cuò)誤信息</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();
//開(kāi)始  

                  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中,提供了幾個(gè)靜態(tài)方法,用來(lái)修改配置文件。

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

獲得應(yīng)用程序下的配置文件,之后再用config進(jìn)行操作。

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

 


 

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

這里寫(xiě)了幾個(gè)類(lèi),主要也是模仿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中,不要帶名稱(chēng)空間,就是xmlns="xxxx一大堆的";

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

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

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

2。設(shè)置權(quán)限

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

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

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

 


 

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

于是,我通過(guò)壓縮項(xiàng)目文件,當(dāng)然沒(méi)有壓縮web.config,因?yàn)閣eb.config是要修改的,在壓縮包里就改不了。所以最后的做法是解壓RAR+文件拷貝web.config!

關(guān)于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();
//解壓開(kāi)始  

            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這個(gè)是就是安裝的RAR.exe路徑!

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

前些天也寫(xiě)過(guò)一篇和RAR相關(guān)的文章:

記錄下關(guān)于調(diào)用RAR解壓縮的問(wèn)題

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

OK,RAR解壓就這么告一段落,接下來(lái),我有一個(gè)App_Data目錄,由于會(huì)往里面寫(xiě)生成的xml,所以為之添加一個(gè)可寫(xiě)權(quán)限!


 

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

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

 

設(shè)置權(quá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);

 

這里是添加了一個(gè)everyone用戶(hù),當(dāng)然也可以換成aspnet用戶(hù),具體看安全性要求給了!后面就給出了所有權(quán)限。

具體關(guān)于權(quán)限的說(shuō)明,多百google度或在vs下看按F1幫助文檔就清楚了!

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

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

 

 


 

用C#進(jìn)行ADSI編程,需要引用添加名稱(chēng)空間:System.DirectoryServices

主要操作類(lèi)是:DirectoryEntry

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

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

以下進(jìn)入代碼階段

 

創(chuàng)建網(wǎng)站
DirectoryEntry iisEntry = new DirectoryEntry("IIS://localhost/w3svc");//獲得IIS節(jié)點(diǎn)
//
創(chuàng)建站點(diǎn)WebSiteID為整形,隨便生成,不重復(fù)即可,可能引發(fā)的問(wèn)題,看我之前的一篇文章:
//
C# 創(chuàng)建網(wǎng)站 無(wú)法啟動(dòng)與停止的問(wèn)題
//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());//這里是綁定多個(gè)IP

site.Invoke("Put""ServerState"4);//4為停止,2為啟動(dòng)
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)站后,要?jiǎng)?chuàng)建默認(rèn)根節(jié)點(diǎn),代碼如下:

 

創(chuàng)建根節(jié)點(diǎn)
//創(chuàng)建默認(rèn)根節(jié)點(diǎn)目錄
                    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身份驗(yàn)證

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

 

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

打完,收工!

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

這里提供一下創(chuàng)建虛擬目錄的大體方法,虛擬目錄是通過(guò)Root節(jié)點(diǎn)去創(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";//這里是一個(gè)Root節(jié)點(diǎn)的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身份驗(yàn)證

                siteVDir.Properties["AuthAnonymous"][0= true;//集成win身份驗(yàn)證
                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)站同名檢測(cè):

 

確認(rèn)網(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 
= "站點(diǎn)名稱(chēng)已存在!"
;
                            
return true
;
                        }
                    }
                }
            }
            
return false
;
        }

 

 

 刪除一個(gè)站點(diǎn):

 

站點(diǎn)刪除
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)站:

 

站點(diǎn)停止和啟動(dò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)站與虛擬目錄,接下來(lái)就是要瀏覽網(wǎng)站了,于是,在界面上多加一個(gè)按鈕,點(diǎn)擊瀏覽是順勢(shì)而加了:

代碼就一句:

 

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 開(kāi)啟:

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
;
        }

 

注冊(cè)asp.net:

 

aspnet 注冊(cè)
 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去,于是修改也是成了一種需求!

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

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

這里用的,還是以xml方式操作,比竟類(lèi)都寫(xiě)了,就順路用上了。

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

 

修改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時(shí),雖然是修改了文件,但運(yùn)行在內(nèi)存中的app.config卻還沒(méi)有修改.

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

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

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多