DirectoryEntry

G

Guest

I wanted to know why the output is different & also like to know if C# i can
get the user name using DirectoryEntry > find.


C#
String myADSPath = ("WinNT://"+
Environment.MachineName+",computer");
DirectoryEntry m_drentry = new DirectoryEntry(myADSPath);
// "admin" is user name

DirectoryEntry m_secentry = m_drentry.Children.Find("admin");
m_txt1.Text = m_drentry.Name ; // Output is the name of Computer


Managed C++
String *adsPath = String::Format(S"WinNT://{0},computer",
Environment::MachineName);

DirectoryEntry *computerEntry = new DirectoryEntry(adsPath);
DirectoryEntry *userEntry = computerEntry->Children->Find (S"Admin");

m_txText->Text = userEntry->Name; //Output is the User Name
 
W

Willy Denoyette [MVP]

AbdSol said:
I wanted to know why the output is different & also like to know if C# i
can
get the user name using DirectoryEntry > find.


C#
String myADSPath = ("WinNT://"+
Environment.MachineName+",computer");
DirectoryEntry m_drentry = new DirectoryEntry(myADSPath);
// "admin" is user name

DirectoryEntry m_secentry = m_drentry.Children.Find("admin");
m_txt1.Text = m_drentry.Name ; // Output is the name of Computer


Managed C++
String *adsPath = String::Format(S"WinNT://{0},computer",
Environment::MachineName);

DirectoryEntry *computerEntry = new DirectoryEntry(adsPath);
DirectoryEntry *userEntry = computerEntry->Children->Find (S"Admin");

m_txText->Text = userEntry->Name; //Output is the User Name

There's an error in your C# code....

m_txt1.Text = m_drentry.Name ;
should be....
m_txt1.Text = m_secentry.Name;

Willy.
 
G

Guest

it works, thank you.

Willy Denoyette said:
There's an error in your C# code....

m_txt1.Text = m_drentry.Name ;
should be....
m_txt1.Text = m_secentry.Name;

Willy.
 

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