By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,732 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,732 IT Pros & Developers. It's quick & easy.

current user in Active Directory

P: n/a
Hi,
How do I find the user object for the current user in Active Directory i.e.
the user running my program ?
Regards
Michael
Sep 27 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Michael,

if it is the same for you, the user running your program is at a windowsform
program

Environment.username

I hope this helps,

Cor

"ASGMikeG" <AS******@discussions.microsoft.com> schreef in bericht
news:7F**********************************@microsof t.com...
Hi,
How do I find the user object for the current user in Active Directory
i.e.
the user running my program ?
Regards
Michael

Sep 27 '05 #2

P: n/a
The user running ASP.NET (When running with impersonation)
is System.Security.Principal.WindowsIdentity.GetCurre nt().Name;

Now you have them both :-)

--
Rainier van Slingerlandt
Microsoft Certified Trainer in Software Development.

"ASGMikeG" wrote:
Hi,
How do I find the user object for the current user in Active Directory i.e.
the user running my program ?
Regards
Michael

Sep 27 '05 #3

P: n/a
Rainer,
Thanks - that will get me the user name - how do I then point that at Active
Directory with 100% certainty ?
Regards
Michael
"Rainier" wrote:
The user running ASP.NET (When running with impersonation)
is System.Security.Principal.WindowsIdentity.GetCurre nt().Name;

Now you have them both :-)

--
Rainier van Slingerlandt
Microsoft Certified Trainer in Software Development.

"ASGMikeG" wrote:
Hi,
How do I find the user object for the current user in Active Directory i.e.
the user running my program ?
Regards
Michael

Sep 30 '05 #4

P: n/a
Oke ones you got the current user you will have to connect to Active
directory and get the properties you want. Here is some code that will do
just that.

/// <summary>
/// Connects to the Active Directory and retrieves the value of the
property asked for.
/// </summary>
/// <param name="PropertyName">Name of the property to retrieve the value
for.</param>
/// <returns>Value of the proeprty, string.empty if property not
found.</returns>
internal string getADirectoryValue(string PropertyName)
{
try
{
DirectoryEntry directoryEntry = new DirectoryEntry(@"LDAP://" +
_aDDomain, _aDLogonUser,_aDLogonUserPassword );
DirectorySearcher directorySearcher = new
DirectorySearcher(directoryEntry);
SearchResult searchResult;
directorySearcher.Filter = "(anr=" + _userName + ")";
searchResult = directorySearcher.FindOne();
DirectoryEntry foundEntry = searchResult.GetDirectoryEntry();
return foundEntry.Properties[PropertyName].Value.ToString();
}
catch(Exception ex)
{
System.Diagnostics.Trace.WriteLine(string.Concat(
"Active Directory Property with name : ",
PropertyName,
" Not found or Active Directory logon failed:",
ex.ToString()));
return string.Empty;
}
}
--
Rainier van Slingerlandt
www.slingerlandt.com

Please hit the Yes button If my effort is helpfull.

"ASGMikeG" wrote:
Rainer,
Thanks - that will get me the user name - how do I then point that at Active
Directory with 100% certainty ?
Regards
Michael
"Rainier" wrote:
The user running ASP.NET (When running with impersonation)
is System.Security.Principal.WindowsIdentity.GetCurre nt().Name;

Now you have them both :-)

--
Rainier van Slingerlandt
Microsoft Certified Trainer in Software Development.

"ASGMikeG" wrote:
Hi,
How do I find the user object for the current user in Active Directory i.e.
the user running my program ?
Regards
Michael

Oct 2 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.