System.DirectoryServices and NT 4.0

T

Ty Moffett

I have a vbscript that will pull and print NT 4.0 domain
machine accounts. I am trying to find a way to do this
in C#.

We are NOT using active directory. We have one NT 4.0
domain.

My vbscript code is as follows:

--CODE--
set comps = getobject("WinNT://TULSA")
comps.filter = Array("Computer")

for each comp in comps
wscript.echo comp.name
next
--END CODE--

My C# code is as follows:

--CODE--
static void Main(string[] args)
{
DirectoryEntry myEntry = new DirectoryEntry
("WinNT://MYDOMAINHERE");
DirectorySearcher mySearcher = new
DirectorySearcher(myEntry);
Console.WriteLine(mySearcher.FindAll());


}
--END CODE--

It throws an exception on the FindAll() method.

--EXCEPTION DETAILS--

System.NotSupportedException was unhandled
Message="The provider does not support searching and
cannot search WinNT://MYDOMAINHERE."
Source="System.DirectoryServices"
StackTrace:
at
System.DirectoryServices.DirectorySearcher.FindAll
(Boolean findMoreThanOne)

at
System.DirectoryServices.DirectorySearcher.FindAll()

at test.Program.Main(String[] args) in
C:\Documents and Settings\tmoffett\my documents\visual
studio 2005\Projects\test\test\Program.cs:line 15

at System.AppDomain.nExecuteAssembly(Assembly
assembly, String[] args)

at System.AppDomain.ExecuteAssembly(String
assemblyFile, Evidence assemblySecurity, String[] args)

at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAss
embly()

at
System.Threading.ThreadHelper.ThreadStart_Context(Object
state)

at System.Threading.ExecutionContext.Run
(ExecutionContext executionContext, ContextCallback
callback, Object state)

at System.Threading.ThreadHelper.ThreadStart()

--END EXCEPTION DETAILS--


I substituted my actual domain name for "MYDOMAINHERE".

Is there a way to get a list of the machine accounts in
an NT 4.0 domain with C# and .NET?

Thanks.
 
M

Marc Scheuner [MVP ADSI]

--EXCEPTION DETAILS--
System.NotSupportedException was unhandled
Message="The provider does not support searching and
cannot search WinNT://MYDOMAINHERE."
Source="System.DirectoryServices"
StackTrace:
at
System.DirectoryServices.DirectorySearcher.FindAll
(Boolean findMoreThanOne)

As the error states - the DirectorySearcher class does not support
searching using the WinNT provider - sorry.
Is there a way to get a list of the machine accounts in
an NT 4.0 domain with C# and .NET?

You can always fall back on the straight COM ADSI classes - just add a
reference to the "Active DS Type Library 1.0" COM object. You should
get a reference called "ActiveDs" (or possibly Interop.ActiveDs).

Add a "using ActiveDs;" to your C# code, and you're good to go.
However, searching with the straight ADSI code is a bit messy.

Marc
 
G

Guest

Thanks for your reply. All I'm trying to do is get a
list of all machine accounts in the domain. I don't need
to search or anything to hairy.

I'll poke around in ActiveDS and see what I can find.
Any other suggestions would be greatly appreciated. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top