C#操作IIS的代码

         将C#操作IIS的代码贴出来,方便以后查阅.代码都是以前在网上搜集的,记不得出处了.

ContractedBlock.gif ExpandedBlockStart.gif IISServerState
None.gifusing System;
None.gifusing System.DirectoryServices;
None.gifusing System.Collections;
None.gif
None.gifnamespace OPS.Component
None.gif{
None.gif    /** 
<summary>
None.gif    /// IISWebServer的状态
None.gif    /// 
</summary>
None.gif    public enum IISServerState
None.gif    {
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Starting = 1,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Started = 2,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Stopping = 3,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Stopped = 4,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Pausing = 5,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Paused = 6,
None.gif        /** 
<summary>
None.gif        /// 
None.gif        /// 
</summary>
None.gif        Continuing = 7
None.gif    }
None.gif}
None.gif


ContractedBlock.gif ExpandedBlockStart.gif IISWebServer
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
None.gif
using System.DirectoryServices;
None.gif
None.gif
namespace OPS.Component
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// IISWebServer
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class IISWebServer
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        internal int index = -1;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebVirtualDirCollection WebVirtualDirs;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 网站说明
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string ServerComment = "Way";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 脚本支持
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool AccessScript = true;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 读取
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool AccessRead = true;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 物理路径
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string Path = @"c:\";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 端口
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public int Port = 80;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 目录浏览
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool EnableDirBrowsing = false;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 默认文档
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string DefaultDoc = "index.aspx";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 使用默认文档
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool EnableDefaultDoc = true;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// IISWebServer的状态
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISServerState ServerState
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry server 
= IISManagement.returnIISWebserver(this.index);
InBlock.gif                
if (server == null)
InBlock.gif                    
throw (new Exception("找不到此IISWebServer"));
InBlock.gif                
switch (server.Properties["ServerState"][0].ToString())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
case "2":
InBlock.gif                        
return IISServerState.Started;
InBlock.gif                    
case "4":
InBlock.gif                        
return IISServerState.Stopped;
InBlock.gif                    
case "6":
InBlock.gif                        
return IISServerState.Paused;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return IISServerState.Stopped;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 停止IISWebServer
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public void Stop()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Server;
InBlock.gif            
if (index == -1)
InBlock.gif                
throw (new Exception("在IIS找不到此IISWebServer!"));
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
InBlock.gif                
if (Server != null)
InBlock.gif                    Server.Invoke(
"stop"new object[0]);
InBlock.gif                
else
InBlock.gif                    
throw (new Exception("在IIS找不到此IISWebServer!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("在IIS找不到此IISWebServer!"));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 把基本信息的更改更新到IIS
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public void CommitChanges()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IISManagement.EditIISWebServer(
this);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 启动IISWebServer
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public void Start()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (index == -1)
InBlock.gif                
throw (new Exception("在IIS找不到此IISWebServer!"));
InBlock.gif
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (Server.Properties["Serverbindings"][0].ToString() == ":" + this.Port + ":")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Server.Invoke(
"stop"new object[0]);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
InBlock.gif                
if (Server != null)
InBlock.gif                    Server.Invoke(
"start"new object[0]);
InBlock.gif                
else
InBlock.gif                    
throw (new Exception("在IIS找不到此IISWebServer!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("在IIS找不到此IISWebServer!"));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServer()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            WebVirtualDirs 
= new IISWebVirtualDirCollection(this);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

ContractedBlock.gif ExpandedBlockStart.gif IISWebServerCollection
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
None.gif
namespace OPS.Component
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// IISWebServerCollection 
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class IISWebServerCollection : CollectionBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServer this[int Index]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (IISWebServer)this.List[Index];
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServer this[string ServerComment]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ServerComment 
= ServerComment.ToLower().Trim();
InBlock.gif                IISWebServer list;
InBlock.gif                
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    list 
= (IISWebServer)this.List[i];
InBlock.gif                    
if (list.ServerComment.ToLower().Trim() == ServerComment)
InBlock.gif                        
return list;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
internal void Add_(IISWebServer WebServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.List.Add(WebServer);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebServer"></param>

InBlock.gif        public void Add(IISWebServer WebServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.List.Add(WebServer);
InBlock.gif                IISManagement.CreateIISWebServer(WebServer);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 是否包含指定的网站
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="ServerComment"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool Contains(string ServerComment)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ServerComment 
= ServerComment.ToLower().Trim();
InBlock.gif            
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                IISWebServer server 
= this[i];
InBlock.gif                
if (server.ServerComment.ToLower().Trim() == ServerComment)
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 是否包含指定的网站
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="index"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public bool Contains(int index)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                IISWebServer server 
= this[i];
InBlock.gif                
if (server.index == index)
InBlock.gif                    
return true;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebServers"></param>

InBlock.gif        public void AddRange(IISWebServer[] WebServers)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i <= WebServers.GetUpperBound(0); i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Add(WebServers[i]);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebServer"></param>

InBlock.gif        public void Remove(IISWebServer WebServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((IISWebServer)this.List[i] == WebServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.List.RemoveAt(i);
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            IISManagement.RemoveIISWebServer(WebServer.index);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


ContractedBlock.gif ExpandedBlockStart.gif IISWebVirtualDir
None.gifusing System;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
None.gif
namespace OPS.Component
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// IISWebVirtualDir
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class IISWebVirtualDir
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServer Parent = null;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 虚拟目录名称
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string Name = "Way";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 读取
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool AccessRead = true;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 脚本支持
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool AccessScript = true;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 物理路径
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string Path = @"c:\";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 默认文档
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string DefaultDoc = "index.aspx";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 使用默认文档
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public bool EnableDefaultDoc = true;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 所属的网站的网站说明
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public string WebServer = "";
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebServerName"></param>

InBlock.gif        public IISWebVirtualDir(string WebServerName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (WebServerName.ToString() == "")
InBlock.gif                
throw (new Exception("WebServerName不能为空!"));
InBlock.gif            
this.WebServer = WebServerName;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebVirtualDir()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

ContractedBlock.gif ExpandedBlockStart.gif IISWebVirtualDirCollection
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
None.gif
namespace OPS.Component
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// IISWebVirtualDirCollection
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class IISWebVirtualDirCollection : CollectionBase
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServer Parent = null;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebVirtualDir this[int Index]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return (IISWebVirtualDir)this.List[Index];
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebVirtualDir this[string Name]
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Name 
= Name.ToLower();
InBlock.gif                IISWebVirtualDir list;
InBlock.gif                
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    list 
= (IISWebVirtualDir)this.List[i];
InBlock.gif                    
if (list.Name.ToLower() == Name)
InBlock.gif                        
return list;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif        
internal void Add_(IISWebVirtualDir WebVirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.List.Add(WebVirtualDir);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebVirtualDir"></param>

InBlock.gif        public void Add(IISWebVirtualDir WebVirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            WebVirtualDir.Parent 
= this.Parent;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.List.Add(WebVirtualDir);
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("发生意外错误,可能是某节点将该节点的上级节点作为它自己的子级插入"));
ExpandedSubBlockEnd.gif            }

InBlock.gif            IISManagement.CreateIISWebVirtualDir(WebVirtualDir, 
true);
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebVirtualDirs"></param>

InBlock.gif        public void AddRange(IISWebVirtualDir[] WebVirtualDirs)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i <= WebVirtualDirs.GetUpperBound(0); i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Add(WebVirtualDirs[i]);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="WebVirtualDir"></param>

InBlock.gif        public void Remove(IISWebVirtualDir WebVirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i < this.List.Count; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if ((IISWebVirtualDir)this.List[i] == WebVirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.List.RemoveAt(i);
InBlock.gif                    IISManagement.RemoveIISWebVirtualDir(WebVirtualDir);
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="Parent"></param>

InBlock.gif        public IISWebVirtualDirCollection(IISWebServer Parent)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Parent = Parent;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

ContractedBlock.gif ExpandedBlockStart.gif IISManagement
None.gifusing System;
None.gif
using System.Collections;
None.gif
using System.Collections.Generic;
None.gif
using System.Text;
None.gif
using System.DirectoryServices;
None.gif
None.gif
namespace OPS.Component
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// IISManagement 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class IISManagement
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISWebServerCollection WebServers = new IISWebServerCollection();
InBlock.gif        
internal static string Machinename = "localhost";
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public IISManagement()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            start();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="MachineName">机器名,默认值为localhost</param>

InBlock.gif        public IISManagement(string MachineName)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (MachineName.ToString() != "")
InBlock.gif                Machinename 
= MachineName;
InBlock.gif            start();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void start()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif            DirectoryEntry Root 
= null;
InBlock.gif            DirectoryEntry VirDir;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif            IEnumerator ieRoot;
InBlock.gif            IISWebServer item;
InBlock.gif            IISWebVirtualDir item_virdir;
InBlock.gif            
bool finded = false;
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    item 
= new IISWebServer();
InBlock.gif                    item.index 
= Convert.ToInt32(Server.Name);
InBlock.gif
InBlock.gif                    item.ServerComment 
= (string)Server.Properties["ServerComment"][0];
InBlock.gif                    item.AccessRead 
= (bool)Server.Properties["AccessRead"][0];
InBlock.gif                    item.AccessScript 
= (bool)Server.Properties["AccessScript"][0];
InBlock.gif                    item.DefaultDoc 
= (string)Server.Properties["DefaultDoc"][0];
InBlock.gif                    item.EnableDefaultDoc 
= (bool)Server.Properties["EnableDefaultDoc"][0];
InBlock.gif                    item.EnableDirBrowsing 
= (bool)Server.Properties["EnableDirBrowsing"][0];
InBlock.gif                    ieRoot 
= Server.Children.GetEnumerator();
InBlock.gif
InBlock.gif                    
while (ieRoot.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Root 
= (DirectoryEntry)ieRoot.Current;
InBlock.gif                        
if (Root.SchemaClassName == "IIsWebVirtualDir")
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            finded 
= true;
InBlock.gif                            
break;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
if (finded)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        item.Path 
= Root.Properties["path"][0].ToString();
ExpandedSubBlockEnd.gif                    }

InBlock.gif
InBlock.gif                    item.Port 
= Convert.ToInt32(((string)Server.Properties["Serverbindings"][0]).Substring(1, ((string)Server.Properties["Serverbindings"][0]).Length - 2));
InBlock.gif                    
this.WebServers.Add_(item);
InBlock.gif                    ieRoot 
= Root.Children.GetEnumerator();
InBlock.gif                    
while (ieRoot.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        VirDir 
= (DirectoryEntry)ieRoot.Current;
InBlock.gif                        
if (VirDir.SchemaClassName != "IIsWebVirtualDir" && VirDir.SchemaClassName != "IIsWebDirectory")
InBlock.gif                            
continue;
InBlock.gif                        item_virdir 
= new IISWebVirtualDir(item.ServerComment);
InBlock.gif                        item_virdir.Name 
= VirDir.Name;
InBlock.gif                        item_virdir.AccessRead 
= (bool)VirDir.Properties["AccessRead"][0];
InBlock.gif                        item_virdir.AccessScript 
= (bool)VirDir.Properties["AccessScript"][0];
InBlock.gif                        item_virdir.DefaultDoc 
= (string)VirDir.Properties["DefaultDoc"][0];
InBlock.gif                        item_virdir.EnableDefaultDoc 
= (bool)VirDir.Properties["EnableDefaultDoc"][0];
InBlock.gif                        
if (VirDir.SchemaClassName == "IIsWebVirtualDir")
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            item_virdir.Path 
= (string)VirDir.Properties["Path"][0];
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        
else if (VirDir.SchemaClassName == "IIsWebDirectory")
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
dot.gif{
InBlock.gif                            item_virdir.Path 
= Root.Properties["Path"][0+ @"\" + VirDir.Name;
ExpandedSubBlockEnd.gif                        }

InBlock.gif                        item.WebVirtualDirs.Add_(item_virdir);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建站点
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="iisServer"></param>

InBlock.gif        public static void CreateIISWebServer(IISWebServer iisServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (iisServer.ServerComment.ToString() == "")
InBlock.gif                
throw (new Exception("IISWebServer的ServerComment不能为空!"));
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif            
int i = 0;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (Convert.ToInt32(Server.Name) > i)
InBlock.gif                        i 
= Convert.ToInt32(Server.Name);
InBlock.gif                    
//                    if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" )    
InBlock.gif                    
//                    {
InBlock.gif                    
//                        Server.Invoke("stop",new object[0]);
InBlock.gif                    
//                    }
ExpandedSubBlockEnd.gif
                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            i
++;
InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                iisServer.index 
= i;
InBlock.gif                Server 
= Service.Children.Add(i.ToString(), "IIsWebServer");
InBlock.gif                Server.Properties[
"ServerComment"][0= iisServer.ServerComment;
InBlock.gif                Server.Properties[
"Serverbindings"].Add(":" + iisServer.Port + ":");
InBlock.gif                Server.Properties[
"AccessScript"][0= iisServer.AccessScript;
InBlock.gif                Server.Properties[
"AccessRead"][0= iisServer.AccessRead;
InBlock.gif                Server.Properties[
"EnableDirBrowsing"][0= iisServer.EnableDirBrowsing;
InBlock.gif                Server.Properties[
"DefaultDoc"][0= iisServer.DefaultDoc;
InBlock.gif                Server.Properties[
"EnableDefaultDoc"][0= iisServer.EnableDefaultDoc;
InBlock.gif
InBlock.gif                DirectoryEntry root 
= Server.Children.Add("Root""IIsWebVirtualDir");
InBlock.gif                root.Properties[
"path"][0= iisServer.Path;
InBlock.gif
InBlock.gif
InBlock.gif                Service.CommitChanges();
InBlock.gif                Server.CommitChanges();
InBlock.gif                root.CommitChanges();
ExpandedSubBlockStart.gifContractedSubBlock.gif                root.Invoke(
"AppCreate2"new object[1dot.gif2 });
InBlock.gif                
//Server.Invoke("start",new object[0]);
ExpandedSubBlockEnd.gif
            }

InBlock.gif            
catch (Exception es)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (es);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除IISWebServer
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void RemoveIISWebServer(string ServerComment)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            ServerComment 
= ServerComment.ToLower();
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (Server.Properties["ServerComment"][0].ToString().ToLower() == ServerComment)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Service.Children.Remove(Server);
InBlock.gif                        Service.CommitChanges();
InBlock.gif                        
return;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除IISWebServer
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        public static void RemoveIISWebServer(int index)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry Server 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
InBlock.gif                
if (Server != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Service.Children.Remove(Server);
InBlock.gif                    Service.CommitChanges();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
throw (new Exception("找不到此IISWebServer"));
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("找不到此IISWebServer"));
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 检查是否存在IISWebServer
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="ServerComment">网站说明</param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public static bool ExistsIISWebServer(string ServerComment)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ServerComment 
= ServerComment.Trim();
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server 
= null;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
string comment;
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    comment 
= Server.Properties["ServerComment"][0].ToString().ToLower().Trim();
InBlock.gif                    
if (comment == ServerComment.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return true;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return false;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回指定的IISWebServer
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="ServerComment"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        internal static DirectoryEntry returnIISWebserver(string ServerComment)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ServerComment 
= ServerComment.Trim();
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server 
= null;
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
string comment;
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    comment 
= Server.Properties["ServerComment"][0].ToString().ToLower().Trim();
InBlock.gif                    
if (comment == ServerComment.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        
return Server;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///  返回指定的IISWebServer
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="index"></param>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        internal static DirectoryEntry returnIISWebserver(int index)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Server 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC/" + index);
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                IEnumerator ie 
= Server.Children.GetEnumerator();
InBlock.gif                
return Server;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private static DirectoryEntry getRoot(DirectoryEntry Server)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
foreach (DirectoryEntry child in Server.Children)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string name = child.Name.ToLower();
InBlock.gif                
if (name == "iiswebvirtualdir" || name == "root")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return child;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 修改与给定的IISWebServer具有相同网站说明的站点配置
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="iisServer">给定的IISWebServer</param>

InBlock.gif        public static void EditIISWebServer(IISWebServer iisServer)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (iisServer.index == -1)
InBlock.gif                
throw (new Exception("找不到给定的站点!"));
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":")
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Server.Invoke(
"stop"new object[0]);
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            Server 
= returnIISWebserver(iisServer.index);
InBlock.gif            
if (Server == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("找不到给定的站点!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                Server.Properties[
"ServerComment"][0= iisServer.ServerComment;
InBlock.gif                Server.Properties[
"Serverbindings"][0= ":" + iisServer.Port + ":";
InBlock.gif                Server.Properties[
"AccessScript"][0= iisServer.AccessScript;
InBlock.gif                Server.Properties[
"AccessRead"][0= iisServer.AccessRead;
InBlock.gif                Server.Properties[
"EnableDirBrowsing"][0= iisServer.EnableDirBrowsing;
InBlock.gif                Server.Properties[
"DefaultDoc"][0= iisServer.DefaultDoc;
InBlock.gif                Server.Properties[
"EnableDefaultDoc"][0= iisServer.EnableDefaultDoc;
InBlock.gif
InBlock.gif                DirectoryEntry root 
= getRoot(Server);
InBlock.gif
InBlock.gif                Server.CommitChanges();
InBlock.gif                
if (root != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    root.Properties[
"path"][0= iisServer.Path;
InBlock.gif                    root.CommitChanges();
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                Server.Invoke(
"start"new object[0]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception es)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (es);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 返回所有站点的网站说明
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <returns></returns>

InBlock.gif        public static ArrayList returnIISServerComment()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server;
InBlock.gif
InBlock.gif            ArrayList list 
= new ArrayList();
InBlock.gif            IEnumerator ie 
= Service.Children.GetEnumerator();
InBlock.gif
InBlock.gif            
while (ie.MoveNext())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Server 
= (DirectoryEntry)ie.Current;
InBlock.gif                
if (Server.SchemaClassName == "IIsWebServer")
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    list.Add(Server.Properties[
"ServerComment"][0]);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return list;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 创建虚拟目录
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="iisVir"></param>
ExpandedSubBlockEnd.gif        
/// <param name="deleteIfExist"></param>

InBlock.gif        public static void CreateIISWebVirtualDir(IISWebVirtualDir iisVir, bool deleteIfExist)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (iisVir.Parent == null)
InBlock.gif                
throw (new Exception("IISWebVirtualDir没有所属的IISWebServer!"));
InBlock.gif
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server 
= returnIISWebserver(iisVir.Parent.index);
InBlock.gif
InBlock.gif            
if (Server == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("找不到给定的站点!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            Server 
= getRoot(Server);
InBlock.gif            
if (deleteIfExist)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (DirectoryEntry VirDir in Server.Children)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
dot.gif{
InBlock.gif                        Server.Children.Remove(VirDir);
InBlock.gif                        Server.CommitChanges();
InBlock.gif                        
break;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                DirectoryEntry vir;
InBlock.gif                vir 
= Server.Children.Add(iisVir.Name, "IIsWebVirtualDir");
InBlock.gif                vir.Properties[
"Path"][0= iisVir.Path;
InBlock.gif                vir.Properties[
"DefaultDoc"][0= iisVir.DefaultDoc;
InBlock.gif                vir.Properties[
"EnableDefaultDoc"][0= iisVir.EnableDefaultDoc;
InBlock.gif                vir.Properties[
"AccessScript"][0= iisVir.AccessScript;
InBlock.gif                vir.Properties[
"AccessRead"][0= iisVir.AccessRead;
ExpandedSubBlockStart.gifContractedSubBlock.gif                vir.Invoke(
"AppCreate2"new object[1dot.gif2 });
InBlock.gif
InBlock.gif                Server.CommitChanges();
InBlock.gif                vir.CommitChanges();
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception es)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (es);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除虚拟目录
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="WebServerComment">站点说明</param>
ExpandedSubBlockEnd.gif        
/// <param name="VirtualDir">虚拟目录名称</param>

InBlock.gif        public static void RemoveIISWebVirtualDir(string WebServerComment, string VirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            VirtualDir 
= VirtualDir.ToLower();
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server 
= returnIISWebserver(WebServerComment);
InBlock.gif
InBlock.gif            
if (Server == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("找不到给定的站点!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            Server 
= getRoot(Server);
InBlock.gif            
foreach (DirectoryEntry VirDir in Server.Children)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (VirDir.Name.ToLower().Trim() == VirtualDir)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Server.Children.Remove(VirDir);
InBlock.gif                    Server.CommitChanges();
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
throw (new Exception("找不到给定的虚拟目录!"));
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 删除虚拟目录
InBlock.gif        
/// </summary>
ExpandedSubBlockEnd.gif        
/// <param name="iisVir"></param>

InBlock.gif        public static void RemoveIISWebVirtualDir(IISWebVirtualDir iisVir)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DirectoryEntry Service 
= new DirectoryEntry("IIS://" + IISManagement.Machinename + "/W3SVC");
InBlock.gif            DirectoryEntry Server 
= returnIISWebserver(iisVir.Parent.index);
InBlock.gif
InBlock.gif            
if (Server == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
throw (new Exception("找不到给定的站点!"));
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            Server 
= getRoot(Server);
InBlock.gif            
foreach (DirectoryEntry VirDir in Server.Children)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (VirDir.Name.ToLower().Trim() == iisVir.Name.ToLower())
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Server.Children.Remove(VirDir);
InBlock.gif                    Server.CommitChanges();
InBlock.gif                    
return;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
throw (new Exception("找不到给定的虚拟目录!"));
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值