DirectoryInfo di = new DirectoryInfo(path);
DirectorySecurity ds = di.GetAccessControl();
FileSystemAccessRule ar1 = new FileSystemAccessRule(Account, FileSystemRights.FullControl, AccessControlType.Allow);
FileSystemAccessRule ar2 = new FileSystemAccessRule(Account, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
ds.AddAccessRule(ar1);
ds.AddAccessRule(ar2);
di.SetAccessControl(ds);
}
public static void RemoveFileSecurity(string Account, string pathname)
{
DirectoryInfo dirinfo = new DirectoryInfo(pathname);
if ((dirinfo.Attributes & FileAttributes.ReadOnly) != 0)
{
dirinfo.Attributes = FileAttributes.Normal;
}
//取得访问控制列表
DirectorySecurity dirsecurity = dirinfo.GetAccessControl();
dirsecurity.RemoveAccessRuleAll(new FileSystemAccessRule(Account, FileSystemRights.FullControl, AccessControlType.Allow));
dirinfo.SetAccessControl(dirsecurity);
}
//修改NT用户密码
//传入参数:Username用户名,Userpassword用户新密码
public static bool InitNTPwd(string Username, string Userpassword)
{
try
{
DirectoryEntry obComputer = new DirectoryEntry("WinNt://" + Environment.MachineName);
DirectoryEntry obUser = obComputer.Children.Find(Username, "webaccount");
obUser.Invoke("SetPassword", Userpassword);
obUser.CommitChanges();
obUser.Close();
obComputer.Close();
return true;
}
catch
{
return false;
}
}
//删除NT用户
//传入参数:Username用户名
public static bool DelNTUser(string strNodeName)
{
DirectoryEntry User;
DirectoryEntry AD=null;
try
{
AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
User = AD.Children.Find(strNodeName, "User");
AD.Children.Remove(User);
return true;
}
catch
{
return false;
}
finally
{
AD.Dispose();
}
}
/// <summary>
/// 获取主机头
/// </summary>
/// <param name="siteName"></param>
/// <returns></returns>
public static string[] GetHeadhost(string siteName)
{
ArrayList list = new ArrayList();
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
PropertyValueCollection Thostnames = siteEntry.Properties["ServerBindings"];
for (int i = 0; i < Thostnames.Count; i++)
{
list.Add(Thostnames[i].ToString());
}
if (list.Count == 0)
return new string[0];
else
return (string[])list.ToArray(typeof(string));
}
public static void CleareHosthead(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
PropertyValueCollection Thostnames = siteEntry.Properties["ServerBindings"];
Thostnames.Clear();
siteEntry.CommitChanges();
}
public static string RestartIIS()
{
string retstr = string.Empty;
try
{
Process.Start("iisreset","stop");
}
catch (Exception ex)
{
retstr = ex.Message;
}
return retstr;
}
/// <summary>
/// 配置主机头
/// </summary>
/// <param name="headhost"></param>
/// <returns></returns>
public static void ConfigHeadhost(string siteName, string headhost)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
PropertyValueCollection Thostnames = siteEntry.Properties["ServerBindings"];
Thostnames.Add(headhost);
siteEntry.CommitChanges();
}
//创建NT用户
//传入参数:Username要创建的用户名,Userpassword用户密码,Path主文件夹路径
public static bool CreateNTUser(string Username, string Userpassword, string Path)
{
DirectoryEntry obDirEntry = null;
try
{
obDirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名
obUser.Properties["FullName"].Add(Username); //用户全称
obUser.Invoke("SetPassword", Userpassword); //用户密码
obUser.Invoke("Put", "Description", "站点相对应的帐号");//用户详细描述
//obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码
obUser.Invoke("Put", "UserFlags", 66049); //密码永不过期
//obUser.Invoke("Put", "UserFlags", 0x0040);//用户不能更改密码s
obUser.CommitChanges();//保存用户
DirectoryEntry grp = obDirEntry.Children.Find("webaccount", "group");//Users组
if (grp.Name != "")
{
grp.Invoke("Add", obUser.Path.ToString());//将用户添加到某组
}
return true;
}
catch
{
return false;
}
}
//创建IIS_wpg进程用户
//传入参数:Username要创建的用户名,Userpassword用户密码,Path主文件夹路径
public static bool CreateAppUser(string Username, string Userpassword, string Path)
{
DirectoryEntry obDirEntry = null;
try
{
obDirEntry = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry obUser = obDirEntry.Children.Add(Username, "User"); //增加用户名
obUser.Properties["FullName"].Add(Username); //用户全称
obUser.Invoke("SetPassword", Userpassword); //用户密码
obUser.Invoke("Put", "Description", "站点相对应的帐号");//用户详细描述
//obUser.Invoke("Put","PasswordExpired",1); //用户下次登录需更改密码
obUser.Invoke("Put", "UserFlags", 66049); //密码永不过期
//obUser.Invoke("Put", "UserFlags", 0x0040);//用户不能更改密码s
obUser.CommitChanges();//保存用户
DirectoryEntry grp = obDirEntry.Children.Find("IIS_WPG", "group");//Users组
if (grp.Name != "")
{
grp.Invoke("Add", obUser.Path.ToString());//将用户添加到某组
}
return true;
}
catch
{
return false;
}
}
/// <summary>
/// 删除应用程序池
/// </summary>
/// <returns></returns>
public static void DeleteAppPoolByName(string AppPoolName)
{
try
{
DirectoryEntry IISEntryPool = new DirectoryEntry("IIS://localhost/w3svc/AppPools");
foreach (DirectoryEntry de in IISEntryPool.Children)
{
if (String.Compare(de.Name, AppPoolName, true) == 0)
{
IISEntryPool.Children.Remove(de);
IISEntryPool.CommitChanges();
}
}
}
catch (Exception ex)
{
//错误处理过程
}
}
/// <summary>
/// method是管理应用程序池的方法,有三种Start、Stop、Recycle,而AppPoolName是应用程序池名称
/// </summary>
/// <param name="method"></param>
/// <param name="AppPoolName"></param>
public static void ConfigAppPool(string method, string AppPoolName)
{
DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");
findPool.Invoke(method, null);
appPool.CommitChanges();
appPool.Close();
}
/// <summary>
/// 创建一个新的应用程序池
/// </summary>
/// <param name="AppPoolName"></param>
public static void CreateAppPool(string AppPoolName,string WAMUserName,string WAMUserPass)
{
DirectoryEntry newpool;
DirectoryEntry apppools = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");
newpool = apppools.Children.Add(AppPoolName, "IIsApplicationPool");
newpool.Properties["AppPoolIdentityType"][0] = 0x00000003;
newpool.Properties["WAMUserName"][0] = WAMUserName;
newpool.Properties["WAMUserPass"][0] = WAMUserPass;
newpool.CommitChanges();
}
/**/
/// <summary>
/// 创建站点
/// </summary>
/// <param name="iisServer"></param>
public static void CreateIISWebServer(NewWebSiteInfo siteInfo, string iisp, string iisc, string maxweight, bool ishtml, bool isaspnet, bool asp, bool php, int sessiontimeout)
{
if (siteInfo.CommentOfWebSite.ToString() == "")
throw (new Exception("IISWebServer的ServerComment不能为空!"));
DirectoryEntry Service = new DirectoryEntry("IIS://" + Environment.MachineName + "/W3SVC");
DirectoryEntry Server;
int i = 0;
IEnumerator ie = Service.Children.GetEnumerator();
while (ie.MoveNext())
{
Server = (DirectoryEntry)ie.Current;
if (Server.SchemaClassName == "IIsWebServer")
{
if (Convert.ToInt32(Server.Name) > i)
i = Convert.ToInt32(Server.Name);
// if( Server.Properties["Serverbindings"][0].ToString() == ":" + iisServer.Port + ":" )
// {
// Server.Invoke("stop",new object[0]);
// }
}
}
i++;
try
{
// iisServer.index = i;
Server = Service.Children.Add(i.ToString(), "IIsWebServer");
Server.Properties["ServerComment"][0] = siteInfo.CommentOfWebSite;
Server.Properties["Serverbindings"].Add(siteInfo.BindString);
Server.Properties["AccessScript"][0] = false;
Server.Properties["AccessRead"][0] = true;
Server.Properties["EnableDirBrowsing"][0] = false;
Server.Properties["LogFileDirectory"].Value = siteInfo.WebPath.Replace("wwwroots", "Logfiles");
Server.Properties["MaxBandwidth"].Value = Convert.ToInt32(maxweight) * 1024;
Server.Properties["MaxConnections"].Value = Convert.ToInt32(iisc);
Server.Properties["DefaultDoc"][0] = "index.htm,Default.htm,index.asp,Default.asp,index.aspx,Default.aspx,index.php,default.php";
Server.Properties["EnableDefaultDoc"][0] = true;
Server.Properties["AspEnableParentPaths"].Value = true;
Server.Properties["AspRequestQueueMax"].Value = iisp;
Server.Properties["AspSessionTimeout"].Value = sessiontimeout;
Server.Properties["AppPoolId"].Value = siteInfo.CommentOfWebSite;
Server.Properties["AnonymousUserName"].Value = siteInfo.CommentOfWebSite;
Server.Properties["AnonymousUserPass"].Value = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(siteInfo.CommentOfWebSite + "wenweifeng", "md5");
if (php == false && asp == false && isaspnet == false)
{
Server.Properties["AccessScript"][0] = false;//纯脚本
}
else
{
Server.Properties["AccessScript"][0] = true;//纯脚本
//继续判断是否支持PHP,ASP,和ASP.Net
if (php & asp & isaspnet)
{
//三种都支持的情况下
Server.Properties["ScriptMaps"].Value = GetScriptRun(1);
}
else if (php & asp & (!isaspnet))
{
//只支持ASP与PHP的情况下
Server.Properties["ScriptMaps"].Value = GetScriptRun(4);
}
else if ((!php) & asp & isaspnet)
{
//只支持ASP与Asp.NET的情况下
Server.Properties["ScriptMaps"].Value = GetScriptRun(3);
}
else if ((!php) & asp & (!isaspnet))
{
//只支持ASP的情况下
Server.Properties["ScriptMaps"].Value = GetScriptRun(2);
}
else
{
//只支持ASP
Server.Properties["ScriptMaps"].Value = GetScriptRun(2);
}
}
DirectoryEntry root = Server.Children.Add("Root", "IIsWebVirtualDir");
root.Properties["path"][0] = siteInfo.WebPath;
//root.Properties["AppIsolated"].Value = 2;
Service.CommitChanges();
Server.CommitChanges();
root.CommitChanges();
root.Invoke("AppCreate2", new object[1] {2});
//Server.Invoke("start",new object[0]);
}
catch (Exception es)
{
throw (es);
}
}
#region 根据路径构造Entry的方法
/// <summary>
/// 根据是否有用户名来判断是否是远程服务器。
/// 然后再构造出不同的DirectoryEntry出来
/// </summary>
/// <param name="entPath">DirectoryEntry的路径</param>
/// <returns>返回的是DirectoryEntry实例</returns>
public static DirectoryEntry GetDirectoryEntry(string entPath)
{
DirectoryEntry ent;
if (UserName == null)
{
ent = new DirectoryEntry(entPath);
}
else
{
// ent = new DirectoryEntry(entPath, HostName+"\"+UserName, Password, AuthenticationTypes.Secure);
ent = new DirectoryEntry(entPath, UserName, Password, AuthenticationTypes.Secure);
}
return ent;
}
#endregion
#region 添加,删除网站的方法
/// <summary>
/// 创建一个新的网站。根据传过来的信息进行配置
/// </summary>
/// <param name="siteInfo">存储的是新网站的信息</param>
public static void CreateNewWebSite(NewWebSiteInfo siteInfo, string iisp, string iisc, string maxweight, bool ishtml, bool isaspnet, bool asp, bool php,int sessiontimeout)
{
if (!EnsureNewSiteEnavaible(siteInfo.BindString))
{
//throw new DuplicatedWebSiteException("已经有了这样的网站了。" + Environment.NewLine + siteInfo.BindString);
}
else
{
string entPath = String.Format("IIS://{0}/w3svc", HostName);
DirectoryEntry rootEntry = GetDirectoryEntry(entPath);
string newSiteNum = GetNewWebSiteID();
DirectoryEntry newSiteEntry = rootEntry.Children.Add(newSiteNum, "IIsWebServer");
newSiteEntry.CommitChanges();
newSiteEntry.Properties["ServerBindings"].Value = siteInfo.BindString;
newSiteEntry.Properties["ServerComment"][0] = siteInfo.CommentOfWebSite;
//应用程序部分
newSiteEntry.Properties["KeyType"].Value = "IIsWebServer";
//判断为HTML主机则将应用FALSE,判断依据为ASP,PHP,ASPNET都为False
newSiteEntry.Properties["AccessRead"][0] = true;//读
newSiteEntry.Properties["AccessExecute"][0] = false;
if (php == false && asp == false && isaspnet == false)
{
newSiteEntry.Properties["AccessScript"][0] = false;//纯脚本
}
else
{
newSiteEntry.Properties["AccessScript"][0] = true;//纯脚本
//继续判断是否支持PHP,ASP,和ASP.Net
if (php & asp & isaspnet)
{
//三种都支持的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(1);
}
else if (php & asp & (!isaspnet))
{
//只支持ASP与PHP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(4);
}
else if ((!php) & asp & isaspnet)
{
//只支持ASP与Asp.NET的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(3);
}
else if ((!php) & asp & (!isaspnet))
{
//只支持ASP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(2);
}
else
{
//只支持ASP
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(2);
}
}
//newSiteEntry.Properties["AppIsolated"].Value = 2;
//站点的日志文件
newSiteEntry.Properties["LogFileDirectory"].Value = siteInfo.WebPath.Replace("wwwroots", "Logfiles");
//站点的最大带宽
newSiteEntry.Properties["MaxBandwidth"].Value = Convert.ToInt32(maxweight)*1024;
//站点的最大连接客户数
newSiteEntry.Properties["MaxConnections"].Value =Convert.ToInt32(iisc);
newSiteEntry.CommitChanges();
DirectoryEntry vdEntry = newSiteEntry.Children.Add("root", "IIsWebVirtualDir");
// vdEntry.Invoke("AppCreate2", 2);
vdEntry.Properties["AppRoot"].Value = "LM/W3SVC/" + newSiteNum + "/Root";
vdEntry.Properties["Path"][0] = siteInfo.WebPath;
vdEntry.Properties["EnableDefaultDoc"][0] = false;
vdEntry.Properties["AppFriendlyName"].Value = "默认应用程序";
vdEntry.Properties["AppPoolId"].Value = siteInfo.CommentOfWebSite;
vdEntry.Properties["AnonymousUserName"].Value = siteInfo.CommentOfWebSite;
vdEntry.Properties["AnonymousUserPass"].Value = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(siteInfo.CommentOfWebSite + "wenweifeng", "md5");
vdEntry.Properties["DefaultDoc"][0] = "index.htm,Default.htm,index.asp,Default.asp,index.aspx,Default.aspx,index.php,default.php";
//vdEntry.Properties["DefaultDocFooter"].Value = false;//有严重的问题导致数据无效
vdEntry.Properties["EnableDefaultDoc"][0] = true;
vdEntry.Properties["EnableDirBrowsing"][0] = false;//目录浏览
vdEntry.Properties["AccessWrite"][0] = false;//写入
// vdEntry.Properties["AppAllowClientDebug"].Value = true;
vdEntry.Properties["AspEnableParentPaths"].Value = true;
// vdEntry.Properties["AspAllowSessionState"].Value = true;
//ASP应用程序的Sessiontimeout会话时间
//vdEntry.Properties["AspSessionTimeout"].Value = sessiontimeout;
vdEntry.Properties["AspScriptLanguage"].Value = "VBScript";
//vdEntry.Properties["AspScriptTimeout"].Value = 90;
// ASP最大查询并发数
vdEntry.Properties["AspRequestQueueMax"].Value = iisp;
// vdEntry.Properties["AspScriptErrorSentToBrowser"].Value = false;
//Type typ = vdEntry.Properties["IPSecurity"][0].GetType();
//object IPSecurity = vdEntry.Properties["IPSecurity"][0];
//object[] newIPDenyList = new object[4];
//newIPDenyList[0] = "192.168.1.1, 255.255.255.255";
//newIPDenyList[1] = "192.168.1.2, 255.255.255.255";
//newIPDenyList[2] = "192.168.1.3, 255.255.255.255";
//newIPDenyList[3] = "192.168.1.4, 255.255.255.255";
//typ.InvokeMember("IPDeny",
// BindingFlags.DeclaredOnly |
// BindingFlags.Public | BindingFlags.NonPublic |
// BindingFlags.Instance | BindingFlags.SetProperty,
// null, IPSecurity, new object[] { newIPDenyList });
//vdEntry.Properties["IPSecurity"][0] = IPSecurity;
vdEntry.Invoke("AppCreate2", new object[1] { 2 });
vdEntry.CommitChanges();
rootEntry.CommitChanges();
}
}
public static string[] GetScriptRunver2(int i)
{
string[] _script1;
string[] _script2;
string[] _script3;
string[] _script4;
string[] ret;
//支持 asp/asp.net/php
_script1 = new string[27]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asax,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ascx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ashx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asmx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".aspx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".axd,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".config,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".cs,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".csproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".licx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".php,"+"\"D:\\Program Files\\PHP\\php5isapi.dll\",5",
".rem,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".resources,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".resx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".soap,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".vb,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vbproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vsdisco,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".webinfo,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
};
//支持 asp
_script2 = new string[8]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST"
};
//支持 asp/asp.net
_script3 = new string[26]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asax,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ascx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ashx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asmx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".aspx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".axd,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".config,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".cs,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".csproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".licx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
//".php,"+@"c:\windows"+@"\system32\php5isapi.dll,5",
".rem,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".resources,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".resx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".soap,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".vb,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vbproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vsdisco,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".webinfo,"+@"c:\windows"+@"\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG"
};
//支持 asp/php
_script4 = new string[9]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".php,"+"\"D:\\Program Files\\PHP\\php5isapi.dll\",5",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST"
};
if (i == 1)
{
ret = _script1;
}
else if (i == 2)
{
ret = _script2;
}
else if (i == 3)
{
ret = _script3;
}
else
{
ret = _script4;
}
return ret;
}
public static string[] GetScriptRun(int i)
{
string [] _script1;
string [] _script2;
string [] _script3;
string [] _script4;
string[] ret;
//支持 asp/asp.net/php
_script1 = new string[27]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asax,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ascx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ashx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asmx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".aspx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".axd,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".config,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".cs,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".csproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".licx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".php,"+"\"D:\\Program Files\\PHP\\php5isapi.dll\",5",
".rem,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".resources,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".resx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".soap,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".vb,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vbproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vsdisco,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".webinfo,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
};
//支持 asp
_script2 = new string[8]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST"
};
//支持 asp/asp.net
_script3 = new string[26]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asax,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ascx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".ashx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asmx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".aspx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".axd,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".config,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".cs,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".csproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".licx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
//".php,"+@"c:\windows"+@"\system32\php5isapi.dll,5",
".rem,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".resources,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".resx,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".soap,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".vb,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vbproj,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG",
".vsdisco,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,1,GET,HEAD,POST,DEBUG",
".webinfo,"+@"c:\windows"+@"\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll,5,GET,HEAD,POST,DEBUG"
};
//支持 asp/php
_script4 = new string[9]{".asa,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".asp,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cdx,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".cer,"+@"c:\windows"+@"\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE",
".idc,"+@"c:\windows"+@"\system32\inetsrv\httpodbc.dll,5,GET,POST",
".php,"+"\"D:\\Program Files\\PHP\\php5isapi.dll\",5",
".shtm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".shtml,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST",
".stm,"+@"c:\windows"+@"\system32\inetsrv\ssinc.dll,5,GET,POST"
};
if (i == 1)
{
ret = _script1;
}
else if (i == 2)
{
ret = _script2;
}
else if (i == 3)
{
ret = _script3;
}
else
{
ret = _script4;
}
return ret;
}
/// <summary>
/// 获取网站绑定的目录
/// </summary>
/// <param name="siteName"></param>
/// <returns></returns>
public static string GetWebPath(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
DirectoryEntry vdEntry = siteEntry.Children.Find("root", "IIsWebVirtualDir");
return vdEntry.Properties["Path"].Value.ToString();
}
/// <summary>
/// 获取网站文件头文档
/// </summary>
/// <param name="siteName"></param>
/// <returns></returns>
public static string GetDefautdoclist(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
DirectoryEntry vdEntry = siteEntry.Children.Find("root", "IIsWebVirtualDir");
return vdEntry.Properties["DefaultDoc"].Value.ToString();
}
/// <summary>
/// 设置网站文件头文档
/// </summary>
/// <param name="siteName"></param>
/// <param name="defdoc"></param>
/// <returns></returns>
public static void SetDefautdoclist(string siteName, string defdoc)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
DirectoryEntry vdEntry = siteEntry.Children.Find("root", "IIsWebVirtualDir");
vdEntry.Properties["DefaultDoc"].Value = defdoc;
vdEntry.CommitChanges();
siteEntry.CommitChanges();
}
public static string GetASPNETVERSION(string siteName)
{
string Version = "1.1";
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry newSiteEntry = GetDirectoryEntry(siteEntPath);
if (newSiteEntry.Properties["ScriptMaps"][1].ToString().IndexOf("v2.0")>0)
{
Version = "2.0";
}
//PropertyValueCollection valueCollection = newSiteEntry.Properties["ScriptMaps"];
//for (int i = 0; i < valueCollection.Count; i++)
//{
// Version += ("[" + i.ToString() + "] =" + valueCollection[i].ToString() + " ");
//}
return Version;
}
/// <summary>
/// 设置ASP.net 的版本
/// </summary>
/// <param name="siteName"></param>
/// <param name="version"></param>
public static void SetASPNETVERSION(string siteName,string version,bool asp,bool php,bool isaspnet)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry newSiteEntry = GetDirectoryEntry(siteEntPath);
newSiteEntry.Properties["ScriptMaps"].Clear();
if (version == "1.1")
{
if (php & asp & isaspnet)
{
//三种都支持的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRun(1);
}
else if (php & asp & (!isaspnet))
{
//只支持ASP与PHP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRun(4);
}
else if ((!php) & asp & isaspnet)
{
//只支持ASP与Asp.NET的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRun(3);
}
else if ((!php) & asp & (!isaspnet))
{
//只支持ASP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRun(2);
}
else
{
//只支持ASP
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRun(2);
}
}
else
{
//asp.net 2.0
if (php & asp & isaspnet)
{
//三种都支持的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(1);
}
else if (php & asp & (!isaspnet))
{
//只支持ASP与PHP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(4);
}
else if ((!php) & asp & isaspnet)
{
//只支持ASP与Asp.NET的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(3);
}
else if ((!php) & asp & (!isaspnet))
{
//只支持ASP的情况下
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(2);
}
else
{
//只支持ASP
newSiteEntry.Properties["ScriptMaps"].Value = GetScriptRunver2(2);
}
}
newSiteEntry.CommitChanges();
}
/// <summary>
/// 获取ASP脚本自定义错误到游览器
/// </summary>
/// <param name="siteName"></param>
/// <returns></returns>
public static string AspScriptErrorSentToBrowser(string siteName)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
DirectoryEntry vdEntry = siteEntry.Children.Find("root", "IIsWebVirtualDir");
return vdEntry.Properties["AspScriptErrorSentToBrowser"].Value.ToString() + "|" + vdEntry.Properties["AspScriptErrorMessage"].Value.ToString();
}
public static void SetAspScriptErrorSentToBrowser(string siteName, string Message, bool configbool)
{
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
DirectoryEntry vdEntry = siteEntry.Children.Find("root", "IIsWebVirtualDir");
vdEntry.Properties["AspScriptErrorSentToBrowser"].Value = configbool;
vdEntry.Properties["AspScriptErrorMessage"].Value = Message;
vdEntry.CommitChanges();
siteEntry.CommitChanges();
}
public static string[] GetWebinfo(string siteName)
{
ArrayList list = new ArrayList();
string siteNum = GetWebSiteNum(siteName);
string siteEntPath = String.Format("IIS://{0}/w3svc/{1}", HostName, siteNum);
DirectoryEntry siteEntry = GetDirectoryEntry(siteEntPath);
//list.Add(siteEntry.SchemaClassName.ToString());
list.Add("绑定信息" + " " + siteEntry.Properties["ServerBindings"].Value.ToString());
list.Add("站点注释" + " " + siteEntry.Properties["ServerComment"].Value.ToString());
list.Add("节点类型" + "$" + siteEntry.Properties["KeyType"].Value.ToString());
list.Add("读取" + "$" + siteEntry.Properties["AccessRead"][0].ToString());
list.Add("纯脚本" + "$" + siteEntry.Properties["AccessScript"][0].ToString());
list.Add("任意文件执行" + "$" + siteEntry.Properties["AccessExecute"][0].ToString());
list.Add("进程运行" + "$" + siteEntry.Properties["AppIsolated"].Value.ToString());
list.Add("日志目录" + "$" + siteEntry.Properties["LogFileDirectory"].Value.To
请发表评论