C#中利用System.DirectoryServices程序创建IIS虚拟目录

来源:互联网 发布:手游脚本软件 编辑:程序博客网 时间:2024/05/22 00:14

C#中利用System.DirectoryServices程序创建IIS虚拟目录:

首先添加System.DirectoryServices.Dll的引用后:

using System.DirectoryServices;
//首先添加System.DirectoryServices.Dll的引用后:

//声明两个DirectoryEntry对像

//de和myde
try
{
            DirectoryEntry de 
= new DirectoryEntry("IIS://你的服务器名/W3SVC/1/Root");
            de.RefreshCache();
            DirectoryEntry myde 
= de.Children.Add("虚拟目录别名" ,"IIsWebVirtualDir");

            DirectoryEntry myde 
= de.Children.Add(othername, "IIsWebVirtualDir");
            myde.Properties[
"Path"].Insert(0"要设置IIS目录的绝对路径");//插入到IIS
            myde.Invoke("AppCreate"true);//创建
            myde.CommitChanges();//保存更改
            de.CommitChanges();
            de.Close();
            myde.Close();
}

catch
{
//eat a exception
}
原创粉丝点击