14 and 15

  • Thread starter Thread starter Thom Little
  • Start date Start date
T

Thom Little

Dumb questions 14 and 15 ...

14 How to I access the User Name in C#?
15 How do I access the Organization Name in C#?
 
Hi Thom,

Based on my understanding, you want to certain user account's user name and
organization name in C#.

There are many ways to get a user account's name, such as:
1. Using WMI to query Win32_UserAccount class's Name or FullName property.
2. Using WindowsIdentity.GetCurrent().Name property(Just as Jiachuan
stated)

I think the second way is much easier for you.

To access the Organization name, I think you should get it through ADSI.

First, you may get the your user account's DirectoryEntry object, then you
can refer the "Organization Name" through "Organization" attribute. Because
"Organization"'s displayname is "o", you can just do like this:

DirectoryEntry usr =new DirectoryEntry("LDAP://CN=New
User,CN=users,DC=fabrikam,DC=com");
string val = (string) usr.Properties["o"].Value;

For more sample and information, please refer to:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sds/sds/use
r_management.asp

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Thom,

Does my reply make sense to you? Do you still have any concern on this
issue?

Please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Thom,

Thanks very much for your feedback.

Yes, there are a lot of ways to retrieve the user name.
SystemInformation.UserName is really simple :-)

To use ADSI, you should use System.DirectoryServices namespace in .Net.
This namespace is not included in the default assembly, you have to add
this assembly into current project through "Add Reference":

In IDE, select "Reference" node of your project in Solution Explorer. Then,
right click this node and select "Add Reference". Then, you can add
"System.DirectoryServices.dll" in ".Net" tab.

Also, I want to inform you that not all the user has organization
information. It may be empty. You can view certain user account's
organization information in the domain through ADSI Edit tool.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Back
Top