Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Frnds.

How to find the Domain Name Using C#.Net (Windows Application)..

Even if the user loged in as local user then also it has to show the Domain Name.
My code is

label1.Text = Environment.UserDomainName;

But it is returning the systemname when user loged in as local user.

My requirement is it should return the Domain Name.

can anybody help me..


Herman<T>.Instance 1-Aug-11 9:59am    
if a user is not logged in into a domain how do you know to which domain a user should belong?

1 solution

string domainName =
Share this answer
Harish Reddy K 2-Aug-11 0:35am    
Thanks for giving reply..

this is not working in my senario...

DomainName: XYZ

I want to display XYZ. But in your Code it is Displaying

For getting Domain we ca also use Domain.GetCurrentDomain();

Thanks for reply...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900