Solved

How to display Select Computer stantard dialog

Posted on 2004-09-14
8
739 Views
Last Modified: 2012-08-14
I'd like to display standard Select Computer dialog, like the one in Computer Management Console -> Right click -> Select "Connect to Another Computer" -> Browse
How can it be done from C#?
Any other standard network browse dialog also will be OK.

Any help will be appreciated,
Jigit
0
Comment
Question by:Jigit
8 Comments
 
LVL 19

Accepted Solution

by:
Desp earned 500 total points
ID: 12054147
There is no such dialog but you can make your own... eg i am filling all the computers in a listbox:

DirectoryEntry root  = new DirectoryEntry("WinNT:");        
               
foreach (DirectoryEntry dDom in root.Children)                  
      foreach (DirectoryEntry dPC in dDom.Children)                  
            if (dPC.SchemaClassName == "Computer" )
                  listBox1.Items.Add (dDom.Name + "/" + dPC.Name);            

0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12054469
     FolderBrowserDialog di = new FolderBrowserDialog();
      di.ShowDialog();
0
 
LVL 4

Author Comment

by:Jigit
ID: 12054983
tomasX2, thank you. Your suggestion allows to browse for folders, while I need only computers.

Desp, your suggestion is closer to what I need. The only problem I encounter with it is performance. The whole enterprise network is being scanned for all the object.

Is there possibility to limit it only to computers?
Or display only domain controllers and expand their networks on mouse click? (Maybe filling them in a tree view)
Does it support WinNT Networks and Active Directory? What has "LDAP" to do with it?

Thanks,
Jigit
0
 
LVL 19

Expert Comment

by:Desp
ID: 12055413
you can put a line
Application.Doevents();
to improve the performance (compare the performance by commenting the line and run the code again)

for active directory , LDAP thingy check this:
http://www.c-sharpcorner.com/Code/2002/Aug/ListAllComps.asp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:Jigit
ID: 12055749
I'm trying to build my own ComputerBrowserDialog using your suggestions. I'm filling Domain Controllers into TreeView on form load. I'd like to expand a network when user double clicks on it. How can I do it? My code is published below, but it does not react on clicking on a node. Any ideas?

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.DirectoryServices;

namespace MMCTest
{
      /// <summary>
      /// Summary description for BrowseServerForm.
      /// </summary>
      public class BrowseServerForm : System.Windows.Forms.Form
      {
            private System.Windows.Forms.Button okButton;
            private System.Windows.Forms.Button cancelButton;
            private System.Windows.Forms.ListBox listBox1;
            public string ServerName = null;
            private System.Windows.Forms.TreeView computersTreeView;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;

            public BrowseServerForm()
            {
                  //
                  // 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.okButton = new System.Windows.Forms.Button();
                  this.cancelButton = new System.Windows.Forms.Button();
                  this.listBox1 = new System.Windows.Forms.ListBox();
                  this.computersTreeView = new System.Windows.Forms.TreeView();
                  this.SuspendLayout();
                  //
                  // okButton
                  //
                  this.okButton.Location = new System.Drawing.Point(392, 352);
                  this.okButton.Name = "okButton";
                  this.okButton.TabIndex = 1;
                  this.okButton.Text = "OK";
                  this.okButton.Click += new System.EventHandler(this.okButton_Click);
                  //
                  // cancelButton
                  //
                  this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                  this.cancelButton.Location = new System.Drawing.Point(160, 360);
                  this.cancelButton.Name = "cancelButton";
                  this.cancelButton.TabIndex = 2;
                  this.cancelButton.Text = "Cancel";
                  this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
                  //
                  // listBox1
                  //
                  this.listBox1.Location = new System.Drawing.Point(32, 40);
                  this.listBox1.Name = "listBox1";
                  this.listBox1.Size = new System.Drawing.Size(344, 225);
                  this.listBox1.TabIndex = 3;
                  //
                  // computersTreeView
                  //
                  this.computersTreeView.ImageIndex = -1;
                  this.computersTreeView.Location = new System.Drawing.Point(392, 48);
                  this.computersTreeView.Name = "computersTreeView";
                  this.computersTreeView.SelectedImageIndex = -1;
                  this.computersTreeView.Size = new System.Drawing.Size(360, 272);
                  this.computersTreeView.TabIndex = 4;
                  //
                  // BrowseServerForm
                  //
                  this.AcceptButton = this.okButton;
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.CancelButton = this.cancelButton;
                  this.ClientSize = new System.Drawing.Size(786, 418);
                  this.Controls.Add(this.computersTreeView);
                  this.Controls.Add(this.listBox1);
                  this.Controls.Add(this.cancelButton);
                  this.Controls.Add(this.okButton);
                  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
                  this.Name = "BrowseServerForm";
                  this.Text = "Browse Server";
                  this.Load += new System.EventHandler(this.BrowseServerForm_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            private void BrowseServerForm_Load(object sender, System.EventArgs e)
            {

                  computersTreeView.BeforeExpand += new TreeViewCancelEventHandler(computersTreeView_BeforeExpand);
                  
                  DirectoryEntry root  = new DirectoryEntry("WinNT:");    
                  foreach (DirectoryEntry dDom in root.Children)
                  {
                        TreeNode node = new TreeNode();
                        node.Text = dDom.Name;
                        computersTreeView.Nodes.Add ( node );    
                  }
            }

            private void okButton_Click(object sender, System.EventArgs e)
            {
                  this.DialogResult = DialogResult.OK;
                  if ( listBox1.SelectedItem != null )
                  {
                        ServerName = listBox1.SelectedItem.ToString();
                  }
            }

            private void cancelButton_Click(object sender, System.EventArgs e)
            {
                  this.DialogResult = DialogResult.Cancel;
            }

            private void computersTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
            {
                  TreeNode node = sender as TreeNode;
                  if ( node == null ) return;

                  DirectoryEntry root  = new DirectoryEntry("WinNT:");        
                  foreach (DirectoryEntry dDom in root.Children)
                  {
                        if ( dDom.Name != node.Text ) continue;

                        foreach (DirectoryEntry dPC in dDom.Children)              
                              if (dPC.SchemaClassName == "Computer" )
                                    node.Nodes.Add ( dPC.Name);      
                  }
            }
      }
}
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12057875
Change:

  computersTreeView.DoubleClick += new TreeViewCancelEventHandler(computersTreeView_BeforeExpand);

to:

  computersTreeView.DoubleClick += new EventHandler(computersTreeView_DoubleClick);


Change:

  private void computersTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)

to:

  private void computersTreeView_DoubleClick(object sender, EventArgs e)


And finally, change:

  TreeNode node = sender as TreeNode;

to:

  TreeNode node = ((TreeView)sender).SelectedNode;


You may also find this of interest: http://www.codeproject.com/csharp/csenumnetworkresources.asp
0
 
LVL 4

Author Comment

by:Jigit
ID: 12057966
eternal_21, thanks for your comment. Let me argue with you: node expansion may be done not only by double-clicking, but also by presssing "+" on the keyboard or maybe some other event. I've already implemented it using BeforeExpand. So all the points go to Desp, who was the first to suggest this solution.

Thanks to all of you , guys!!!
0
 
LVL 19

Expert Comment

by:Desp
ID: 12061496
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now