Click here to Skip to main content
15,886,691 members
Articles / Programming Languages / C#

C# Server Enumerator

Rate me:
Please Sign up or sign in to vote.
4.81/5 (19 votes)
19 Nov 20032 min read 180.6K   3.3K   52  
Server Enumerator in .NET style
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace NetworkManagement.Demo
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class ServerComboBoxForm : System.Windows.Forms.Form
	{
		private NetworkManagement.ServerComboBox serverCombo1;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.CheckBox checkBox2;
		private System.Windows.Forms.CheckBox checkBox3;
		private System.Windows.Forms.CheckBox checkBox4;
		private System.Windows.Forms.CheckBox checkBox5;
		private System.Windows.Forms.GroupBox groupBox1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ServerComboBoxForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.serverCombo1 = new NetworkManagement.ServerComboBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.checkBox2 = new System.Windows.Forms.CheckBox();
			this.checkBox3 = new System.Windows.Forms.CheckBox();
			this.checkBox4 = new System.Windows.Forms.CheckBox();
			this.checkBox5 = new System.Windows.Forms.CheckBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// serverCombo1
			// 
			this.serverCombo1.AutoRefresh = false;
			this.serverCombo1.DomainName = null;
			this.serverCombo1.Location = new System.Drawing.Point(8, 16);
			this.serverCombo1.Name = "serverCombo1";
			this.serverCombo1.ServerType = NetworkManagement.ServerType.None;
			this.serverCombo1.Size = new System.Drawing.Size(176, 21);
			this.serverCombo1.TabIndex = 0;
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(16, 72);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.TabIndex = 1;
			this.checkBox1.Text = "Workstations";
			this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
			// 
			// checkBox2
			// 
			this.checkBox2.Location = new System.Drawing.Point(16, 96);
			this.checkBox2.Name = "checkBox2";
			this.checkBox2.Size = new System.Drawing.Size(88, 24);
			this.checkBox2.TabIndex = 2;
			this.checkBox2.Text = "SQL Servers";
			this.checkBox2.CheckedChanged += new System.EventHandler(this.checkBox2_CheckedChanged);
			// 
			// checkBox3
			// 
			this.checkBox3.Location = new System.Drawing.Point(136, 72);
			this.checkBox3.Name = "checkBox3";
			this.checkBox3.Size = new System.Drawing.Size(120, 24);
			this.checkBox3.TabIndex = 3;
			this.checkBox3.Text = "Domain Controllers";
			this.checkBox3.CheckedChanged += new System.EventHandler(this.checkBox3_CheckedChanged);
			// 
			// checkBox4
			// 
			this.checkBox4.Location = new System.Drawing.Point(136, 96);
			this.checkBox4.Name = "checkBox4";
			this.checkBox4.Size = new System.Drawing.Size(120, 24);
			this.checkBox4.TabIndex = 4;
			this.checkBox4.Text = "Terminal Servers";
			this.checkBox4.CheckedChanged += new System.EventHandler(this.checkBox4_CheckedChanged);
			// 
			// checkBox5
			// 
			this.checkBox5.Location = new System.Drawing.Point(192, 16);
			this.checkBox5.Name = "checkBox5";
			this.checkBox5.Size = new System.Drawing.Size(72, 24);
			this.checkBox5.TabIndex = 5;
			this.checkBox5.Text = "Domains";
			this.checkBox5.CheckedChanged += new System.EventHandler(this.checkBox5_CheckedChanged);
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(8, 48);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(256, 80);
			this.groupBox1.TabIndex = 6;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Server Type";
			// 
			// ServerComboBoxForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(272, 133);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.checkBox5,
																		  this.checkBox4,
																		  this.checkBox3,
																		  this.checkBox2,
																		  this.checkBox1,
																		  this.serverCombo1,
																		  this.groupBox1});
			this.Name = "ServerComboBoxForm";
			this.Text = "Server List Test";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new ServerComboBoxForm());
		}


		private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
		{
			checkBox5.Checked = false;
			SetMask( checkBox1.Checked, NetworkManagement.ServerType.Workstation);
		}

		private void checkBox2_CheckedChanged(object sender, System.EventArgs e)
		{
			checkBox5.Checked = false;
			SetMask( checkBox2.Checked, NetworkManagement.ServerType.SQLServer);
		}

		private void checkBox3_CheckedChanged(object sender, System.EventArgs e)
		{
			checkBox5.Checked = false;
			SetMask( checkBox3.Checked, NetworkManagement.ServerType.DomainController);
		}

		private void checkBox4_CheckedChanged(object sender, System.EventArgs e)
		{
			checkBox5.Checked = false;
			SetMask( checkBox4.Checked, NetworkManagement.ServerType.TerminalServer );
		}

		private void checkBox5_CheckedChanged(object sender, System.EventArgs e)
		{
			if ( checkBox5.Checked )
				checkBox1.Checked = checkBox2.Checked = checkBox3.Checked = checkBox4.Checked = false;

			SetMask( checkBox5.Checked, NetworkManagement.ServerType.DomainEnum );
		}

		private void SetMask( bool setFlag, NetworkManagement.ServerType flag )
		{
			if ( setFlag )
				serverCombo1.ServerType |= flag;
			else
				serverCombo1.ServerType &= ~flag;
			
			serverCombo1.Refresh();	// requery the combobox
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions