Using system.directoryservices; using system.collections; using system.text.regularexpress; using system.text;
/ ** * @Author Wu Haiyan * @Email wuhy80-usual@yahoo.com * 2004-6-25 The first version * / namespace wuhy.toolbox {///
Public static string username {get {return username;} set {username = value;}}
Public static string password;} set {ing (username.length <= 1) {throw new argumentException ("Yes not specified a good user name. Please specify username");
Password = value;}}
PUBLIC Static Void RemoteConfig (String Hostname, String Username, String Password) {hostname = hostname; username = username; password = password;
Private static string hostname = "localhost"; private static string username; private static string password; #endregion
#REGION Depending on whether the user name is determined if the user name is determined if the user name is determined. /// then construct a different DirectoryEntry out /// summary> /// DirectoryEntry path param> ///
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;} #ENDREGON
#Region Add, delete the website method ///
String entPath = string.format ("IIS: // {0} / w3svc", hostname); DirectoryEntry Rootentry = GetDirectoryEntry (ENTPATH);
String newsitenum = getNewwebsiteId (); DirectoryEntry NewsItem = rootentry.children.add (NewsITenum, "IisWebserver"; newsiteentry.commitchanges ();
NewsiteEntry.properties ["Serverbindings"]. Value = SiteInfo.bindString; newsiteentry.properties ["servercomment"]. value = siteinfo.commentofwebsite; newsiteentry.commitchanges (); newsiteentry.commitchange
DirectoryEntry Vdentry = newsiteentry.children.add ("root", "iiswebvirtualdir); vdenTry.commitchanges ();
VdenTry.properties ["path"]. value = siteinfo.webpath; vdenTry.commitchanges ();
///
Rootentry.children.remove (SiteEntry); rootentry.commitchanges ();} #endregion
#REGION START and STOP Site Method PUBLIC Static Void StartWebsite (String Sitenum = GetWebsitenum (Sitename); string sInamentPath = String.Format ("IIS: // {0} / w3svc / {1}", Hostname, Sitenum); DirectoryEntry SiteEntry = GetDirectoryEntry (SiteEntPath);
SiteEntry.Invoke ("start", new object [] {});
public static void StopWebSite (string siteName) {string siteNum = GetWebSiteNum (siteName); string siteEntPath = String.Format ( "IIS: // {0} / w3svc / {1}", HostName, siteNum); DirectoryEntry siteEntry = GetDirectoryEntry ( SitentPath;
SiteEntry.invoke ("stop", new object [] {});} #endregion
#Region confirms whether the website is the same ///
#Region Gets a website number ///
string entPath = String.Format ( "IIS: // {0} / w3svc", HostName); DirectoryEntry ent = GetDirectoryEntry (entPath); foreach (DirectoryEntry child in ent.Children) {if (child.SchemaClassName == "IIsWebServer" ) {If (child.properties]. Value! = Null) {tmpstr = child.properties ["serverbindings"]. Value.toString (); if (regex.match (tmpswstr) .Success) {Return Child .Name;
IF (child.properties ["servercomment"]. value! = null) {tmpstr = child.properties ["servercomment"]. Value.toString (); if (regex.match (tmpstr) .Success) {Return Child.name }}}} Throw new notfoundwebsiteException ("Did not find the site" siteName);} #ENDREGION
#Region Gets a new website ID method ///
string entPath = String.Format ( "IIS: // {0} / w3svc", HostName); DirectoryEntry ent = GetDirectoryEntry (entPath); foreach (DirectoryEntry child in ent.Children) {if (child.SchemaClassName == "IIsWebServer" ) {Tmpstr = child.name.tostring (); list.add (convert.toint32 (tmpstr));}}
List.sort ();
INT i = 1; Foreach (int J in list) {IF (i == j) {i ;}}
Return I.toString ();} #endregion}
#Region new website information structure Public struct newwebsiteinfo {private string hostip; // the hosts ip address private string portnum; // the new web site port.generally is "80" private string descofwebsite; // Website representation. Generally, the website name of the website. For example, "www.dns.com.cn" private string commentofwebsite; // website comment. Generally also also for the website of the website. Private string WebPath; // The main directory of the website. For example, "E: / TMP"
public NewWebSiteInfo (string hostIP, string portNum, string descOfWebSite, string commentOfWebSite, string webPath) {this.hostIP = hostIP; this.portNum = portNum; this.descOfWebSite = descOfWebSite; this.commentOfWebSite = commentOfWebSite; this.webPath = webPath;} Public string bindstring {get {return string.format ("{0}: {1}: {2}", hostip, portnum, descofwebsite;}}
Public String Commentofwebsite {get {return.com
Public string webpath {get {return weight;}}} #ENDREGON}