views:

354

answers:

1

Hello everyone,

i am working on a windows forms .net 3.5 project in c# and the project uses the following line to get the current user:

Created_By = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

On one box the result is hostname\username but on my box the result is username\hostname. Both boxes run Windows 7 Ultimate.

I searched on google but did not find any explanation.

Any explanation or suggestion is apprectiated,

Dawit

A: 

According to MSDN the Name property should return the user name:

The logon name is in the form DOMAIN\USERNAME.

Is the result produced by the same assembly just on a different machine? And is this machine part of a domain?

Although I have no explanation for the behavior that you are experiencing, you could try the following workaround:

string username = Environment.UserDomainName + "\\" + Environment.UserName;
0xA3
The boxes are different developement machines running both Windows 7 Ultimate. The assembly is built on the different machines based on the same code from TFS.Both machines are not part of a domain.
da8
Thank you for you approach:string username = Environment.UserDomainName + "\\" + Environment.UserName;But the result is the same.
da8
Thx, divo. Your hint helped me to solve the problem.Your code returned the same result thus made clear that the problem was somewhere else.It turned out that the configuration of the second box was wrong and resulted in the weired output.Thx a lot,Dawit
da8