|
-
October 29th, 2002, 03:24 AM
#1
all computer names in a domain
hello,
Does Anyone know how to get all computer names in a domain
Thanx
Amit
-
November 7th, 2002, 09:52 PM
#2
Here is a sample snippet that will hopefully accomplish what you are trying to do.
Note: I wrote this sample from scratch and did not have a domain to test it against. You will need to modify the LDAP string passed to the DirectoryEntry constructor to point to the root of the domain you want to search. Other than that, this should work for you.
You will need to add a reference to System.DirectoryServices.DLL from Projects... References. You will also have to add to the top of your file that uses this routing the following line:
uses System.DirectoryServices;
<--- Snippet starts --->
DirectoryEntry oRoot = new DirectoryEntry("LDAP://DC=mysubdomain,DC=mydomain,DC=com");
DirectorySearcher oSearcher = new DirectorySearcher(oRoot);
oSearcher.Filter = "(objectClass=computer)";
oSearcher.PropertiesToLoad.Add("cn");
SearchResultCollection oResults = oSearcher.FindAll();
foreach (SearchResult oResult in oResults)
{
listBox1.Items.Add(oResult.Properties["cn"].ToString());
}
<--- Snippet ends --->
Hope this helps!
- Robert
-
November 14th, 2002, 10:55 AM
#3
Thnx Robert
can u help me with the provider = WinNT://
Regds
Amit
-
November 14th, 2002, 06:10 PM
#4
Since the WinNT provider does not support "searching" you must do the work yourself. Here is a quick example.
<<<--- Code Snippet Start --->>>
private void SearchTree(DirectoryEntry oTree)
{
if ( 0 == String.Compare(oTree.SchemaClassName, "computer", true) )
listBox1.Items.Add( oTree.Name );
foreach (DirectoryEntry oChild in oTree.Children)
{
SearchTree(oChild);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
DirectoryEntry oRoot = new DirectoryEntry("WinNT://dsaddom");
SearchTree(oRoot);
}
catch (Exception ex)
{
listBox1.Items.Add( ex.Message );
}
}
<<<--- Code Snippet End --->>>
Hope that helps.
- Robert
-
October 27th, 2004, 12:34 PM
#5
Re: all computer names in a domain
I have looked over this and over this and in all other threads but did not find any answers for me. I do want to get the computer names (and IP addresses) on the domain BUt, the code does not seem to work for me.
When running I get an error and this pops up:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()
at Class1.Main(String[] args)
Anyone have an idea or have better exact code or even just some hints would be great help!!
Thank you.
-
October 27th, 2004, 01:11 PM
#6
Re: all computer names in a domain
try doing this as well
WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
string name = MyPrincipal.Identity.Name;
string Type = MyPrincipal.Identity.AuthenticationType;
string Auth = MyPrincipal.Identity.IsAuthenticated.ToString();
here string name gives which domain you belong to..I hope this will help you
- Shash
-
October 27th, 2004, 02:32 PM
#7
Re: all computer names in a domain
How is that going to help me??? I already know what domain I am in. This is the code I am using:
using System;
using System.DirectoryServices;
class Class1
{
[STAThread]
static void Main(string[] args)
{
DirectoryEntry entry = new DirectoryEntry("zeltech.com");
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(objectClass=computer)";
foreach (SearchResult res in searcher.FindAll())
{
Console.WriteLine(res.GetDirectoryEntry().Name.ToString());
}
}
}
It compiles but when I run it I get the error above (in the other part of this conversation).
Any ideas!?
-
October 27th, 2004, 04:29 PM
#8
Re: all computer names in a domain
Try changing your DirectoryEntry constructor to include the proper provider. In other words, if it's a domain, try LDAP://zeltech.com.
Another tip is you might want to be a little more polite with regard to people's suggestions.
-
October 29th, 2004, 05:15 AM
#9
Re: all computer names in a domain
I am sorry about being "rude" about someones suggestion. I did not mean to be, I do thank everyone for their help.
I have also tried the LDAP:// thing and it did not seem to work either???
-
October 29th, 2004, 07:09 AM
#10
Re: all computer names in a domain
Okay, for the windows identity stuff, what do I need to "use" (using System) in the file to get that to work and any others needed for that code? I am really new to c sharp!
Thank you!!
-
October 29th, 2004, 08:09 AM
#11
Re: all computer names in a domain
I found the correct System directives that I needed to use. But, I am still having problems with the LDAP, what are the other choices? What does LDAP stand for?? Thank you.
Last edited by bluid; October 29th, 2004 at 08:41 AM.
-
November 3rd, 2004, 08:07 AM
#12
Re: all computer names in a domain
Anyone want to help me out? I am still having some problems and it is really making me crazy. I appreciate any help that I can get. Thank you.
-
November 3rd, 2004, 09:26 AM
#13
Re: all computer names in a domain
LDAP stands for Lightweight Directory Access Protocol.
Read this page for help:
http://msdn.microsoft.com/library/de...dingADApps.asp
-
November 3rd, 2004, 10:03 AM
#14
Re: all computer names in a domain
Thank you for that info. It was very informative. But I still have a question as to why it is tanking when doing the FindAll function???
-
November 4th, 2004, 01:34 PM
#15
Re: all computer names in a domain
Anyone, anyone?? I really need some help. I can not seem to find anything else but this code for this and I have tried so many different ways and can not get anything to go past the FindAll method (see above).
Any help would be greatly appreciated!! Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|