473,385 Members | 1,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

current user in Active Directory

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
4 3823
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
6
by: Leo_Surf | last post by:
Hello, I need your help adding user in Active Directory from ASP.net website. Could any one provide me the complete code for the html page. As this is my curriculam project and I dont have any...
2
by: Brian Henry | last post by:
is there a way to use the directory service to get the current user logged into active directory? thanks
4
by: ASGMikeG | last post by:
Hi, How do I find the user object for the current user in Active Directory i.e. the user running my program ? Regards Michael
0
by: jakobsgaard | last post by:
It is possible to Map a certificate to a Active Directory User Account from DotNet? Please provide an example. Best regards, Ejnar Jakobsgaard...
4
by: Leszek | last post by:
Hello! I have my webpage (ASP) in domain (IIS 6.0). I need to make a popup with fullname of current user. How can I do this? Maybe someone have any examples? Thanks!
7
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
4
by: Spam Catcher | last post by:
Hello All, I need to integrate my application into Active Directory. My application has the concept of groups, users, and also individual permissions. Users can be part of a group such as...
0
by: shorti | last post by:
We are running DB2 UDB 8.1 fp 14 on AIX using archival logging and online backups. I was running some disaster tests and found my database restore was not restoring to the latest active log. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.