Solved

How to display Select Computer stantard dialog

Posted on 2004-09-14
8
740 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New to SOAP and need some direction 10 83
Angular - break the dataset in chunks? 7 51
Windows Media Player 2 26
Sort GridView by ID Descending 1 13
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

810 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