473,471 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3831
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. ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.