Recently a web project is to pack, find some information, found that the installation of the .NET comes with the Web installer is not very easy to use. It has been packaged. You can automatically configure the database and virtual directory and the config file. You are welcome to mention valuable advice. . using System; using System.Collections; using System.ComponentModel; using System.DirectoryServices; using System.Configuration.Install; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; using System.Text; using System.io; using system.xml;
namespace WebSetupConfig {///
#ndregion public setupconfig () {initializationComponent ();
Protected Override Void Dispose (bool disposing) {if (disponents! = null) {components.dispose ();}} Base.Dispose (Disposing);
#REGION component designer generated code ///
}
///
///
///
/ / Install Configure Public Override Void Install (iDictionary Stateaver); // Database DatabaseDeploy (@ "d: /test.bak", "testdb"); // config file Configure connection string WebConfigDeploy ( @ "Data Source = localhost; database = ztwjmis1; user id = sa; pwd = 123"); // Virtual directory VirtualDirDirDeploy ("Virtualtest", @ "d: / vdir");}}
#REGION IIS Management Class ///
public void get_AnonymousUser () {_AnonymousUserPass = "IUSR_DEVE-SERVER"; _AnonymousUserName = "IUSR_DEVE-SERVER"; VirtualDirectory vDir; try {Hashtable myList = (Hashtable) _virdirs; IDictionaryEnumerator myEnumerator = myList.GetEnumerator (); while (myEnumerator.MoveNext ( )) {vDir = (VirtualDirectory) myEnumerator.Value; if (vDir.AnonymousUserName = "" && vDir.AnonymousUserPass =! "") {_AnonymousUserName = vDir.AnonymousUserName;! _AnonymousUserPass = vDir.AnonymousUserPass; break;}}} catch { _AnonymousUserPass = "IUSR_DEVE-SERVER"; _AnonymousUserName = "IUSR_DEVE-SERVER";}} public string AnonymousUserName {get {return _AnonymousUserName;} set {_AnonymousUserName = value;}} public string AnonymousUserPass {get {return _AnonymousUserPass;} set {_AnonymousUserPass = Value;}} // Server property defines the name of the access machine, which can be IP and calculation name public string server {get {returver;} set {_server = value;}} // Website property definition, for a number, For convenience, using string // Generally, the first host is 1, the second host is 2, and push the public string Website {get {return _Website;} set {_Website = value;}} // The name of the virtual directory Public VirtualDirectories virdirs {get {return_virdirs;} set {_virdirs = value;}} ///
// Connect the server public void connection () {ConnectTOSERVER ();} // For easy to overload public void connect (String strserver) {_server = strser ();} // for easy heavy duty PUBLIC VOID Connect (String STRSERVER , string strWebSite) {_server = strServer; _website = strWebSite; ConnectToServer ();} // determines whether the virtual storage directory public bool Exists (string strVirdir) {return _virdirs.Contains (strVirdir);} // add a virtual directory public Bool create (VirtualDirectory newdir) {string strpath = "IIS: //" _server "/ w3svc /" _Website "/ root /" newdir.name; if (! _ virdirs.contains (newdir.name) || _batchflag) {try {// added to the ROOT Children set to DirectoryEntry newVirDir = rootfolder.Children.Add (newdir.Name, "IIsWebVirtualDir"); newVirDir.Invoke ( "AppCreate", true); newVirDir.CommitChanges (); Rootfolder.commitchanges (); // then update the data UpdatedirInfo (newvirdir, newdir); return true;} catch (exception ee) {// throw new exception (EE.TOSTRING ()); Return False;}} else {return true; // throw new Exception ( "This virtual directory is already exist.");}} // get a virtual directory public VirtualDirectory GetVirDir (string strVirdir) {VirtualDirectory tmp = null; if (_virdirs.Contains (strVirdir )) {TMP = _virdirs.Find (strvirdir); ((VirtualDirectory) _virdirs [strvirdir]). Flag = 2;} else {// throw new Exception ("this Virtual Directory Is Not Exists);} Return TMP;}
/ / Update a virtual directory public void update (VirtualDirectory Dir) {// Judging whether the virtual directory that needs to be changed does IF (_VIRDIRDIRS.CONTAINS (Dir.Name)) {DirectoryEntry Ode = rootfolder.children.find (Dir.name, " IIsWebVirtualDir "); UpdateDirInfo (ode, dir);} else {// throw new Exception (" This virtual directory is not exists ");.}} // delete a virtual directory public void delete (string strVirdir) {if (_virdirs .Contains (STRVIRDIR)) {Object [] Paras = new object [2]; Paras [0] = "IisWebVirtualDir"; // Indicates the virtual directory Paras [1] = Strvird; Rootfolder.Invoke ("delete", PARAS); rootfolder.commitchanges ();} else {// throw new exception ("Can''t delete" strvirdir ", Because it isn''t exists.");}} // Batch update public void Updatebatch () {BatchUpdate;} // Reserved one :-) public void updatebatch (VirtualDirectories vds) {BatchUpdate (VDS);} ///
} // Connection Server Private Void ConnectTOSERVER () {string strpath = "IIS: //" _server "/ w3svc /" _Website "/ root"; try {this.rootfolder = new DirectoryEntry (strpath); _Virdirs = GetVirdirs (this.rootfolder.children;} catch (exception e) {// throw new exception ("Can''t connect to the server [" _server "] ...", e);}} // perform bulk updating private void BatchUpdate (VirtualDirectories vds) {_batchflag = true; foreach (object item in vds.Values) {VirtualDirectory vd = (VirtualDirectory) item; switch (vd.flag) {case 0: break; case 1: Create ( VD); Break; Case 2: Update (VD); Break;}} _batchflag = false;} // Update Stuff PRIVATE VOID UpdatedirInfo (DirectoryEntry DE, VirtualDirectory VD) {de.properties ["AnonymoususerName"] [0] = vd.anonymoususeusername; de.properties ["anonymoususerpass"] [0] = vd.anonymoususeuserpass; de.properties ["accessread"] [0] = vd.accessread; de.properties ["AccessExecute"] [0] = VD. AccessExecute; DE .Properties ["accesswrite"] [0] = vd.accessWrite; de.properties ["authbasic"] [0] = vd.authbasic; de.properties ["authnTlm"] [0] = vd.authntlm; de.properties [ "ContentIndexed"] [0] = vd.ContentIndexed; de.Properties [ "EnableDefaultDoc"] [0] = vd.EnableDefaultDoc; de.Properties [ "EnableDirBrowsing"] [0] = vd.EnableDirBrowsing; de.Properties [ " Accessssl "] [0] = vd.accessssssl; de.properties [" accessscript "] [0] = vd.accessscript; de.properties [" defaultdoc "] [0] = vd.defaultdoc; de.properties ["
Path "] [0] = vd.Path; de.CommitChanges ();} // set the virtual directory acquired private VirtualDirectories GetVirDirs (DirectoryEntries des) {VirtualDirectories tmpdirs = new VirtualDirectories (); foreach (DirectoryEntry de in des) {if ( de.SchemaClassName == "IIsWebVirtualDir") {VirtualDirectory vd = new VirtualDirectory (); vd.Name = de.Name; vd.AccessRead = (bool) de.Properties [ "AccessRead"] [0]; vd.AccessExecute = ( Bool) de.properties ["AccessExecute"] [0]; vd.accessWrite = (bool) de.properties ["accesswrite] [0]; vd.anonymoususeusername = (string) de.properties [" anonymoususername "] [0 ]; Vd.anonymoususeuserpass = (string) de.properties ["anonymoususername"] [0]; vd.authbasic = (bool) de.properties ["authbasic"] [0]; vd.authnTlm = (bool) de.properties ["AuthnTLM"] [0]; vd.contentIndexed = (bool) de.properties ["contentindexed"] [0]; vd.enabledeDefaultdoc = (bool) de.properties ["enabledefaultdoc"] [0]; vd.enableDirbrowsingsing = (BOOL) de.properties ["enabledirbrowsing"] [0]; vd.ac Cessssl = (bool) de.properties ["accessssl"] [0]; vd.accessscript = (bool) de.properties ["accessscript"] [0]; vd.path = (string) de.properties ["path" ] [0]; vd.flag = 0; vd.defaultdoc = (string) de.properties ["defaultdoc"] [0]; tmpdirs.add (vd.name, VD);}} returnitirs;}
}
#endregion #region virtual catalog class ///
public int flag {get {return _flag;} set {_flag = value;}} public bool AccessRead {get {return _read;} set {_read = value;}} public bool AccessWrite {get {return _write;} set {_write = value;}} public bool AccessExecute {get {return _execute;} set {_execute = value;}} public bool AccessSSL {get {return _ssl;} set {_ssl = value;}} public bool AccessScript {get {return _script;} set {_script = value;}} public bool AuthBasic {get {return _authbasic;} set {_authbasic = value;}} public bool AuthNTLM {get {return _authntlm;} set {_authntlm = value;}} public bool ContentIndexed {get { return _indexed;} set {_indexed = value;}} public bool EnableDirBrowsing {get {return _endirbrow;} set {_endirbrow = value;}} public bool EnableDefaultDoc {get {return _endefaultdoc;} set {_endefaultdoc = value;}} public string Name {get {return _name;} set {_name = value;}} public string path {get {RET urn _path;} set {_path = value;}} public string DefaultDoc {get {return _defaultdoc;} set {_defaultdoc = value;}} public string AnonymousUserName {get {return _ausername;} set {_ausername = value;}} public string AnonymousUserPass {get {return _auserpass;} set {_auserpass = value;}}} #endregion #region virtual directory collections ///