how to get current username in .net using c#?
+6
A:
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
Juan Manuel
2009-08-06 17:41:07
Hi Juan, I got this error: Error 2 Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Kombucha
2009-08-06 17:44:11
How is this different than `Environment.UserName`?
280Z28
2009-08-06 17:44:23
@Yonita... `string username =.....`??
280Z28
2009-08-06 17:44:59
Well, you have to assign that value to something. Edited.
Juan Manuel
2009-08-06 17:45:16
@Yonita did you assign the value to something?
ghills
2009-08-06 17:45:20
You are ALL correct, I didn't - It's working now :) thank you sO much smart people in stackoverflow. The Best +1
Kombucha
2009-08-06 17:47:33
+1
A:
System.Security.Principal.WindowsIdentity.GetCurrent().Name
that be the logon name
John Cuckaroo
2009-08-06 17:42:50
+1
A:
You may also want to try using:
Environment.UserName;
Like this...:
string j = "Your WindowsXP Account Name is: " + Environment.UserName;
Hope this has been helpful.
baeltazor
2009-08-07 17:58:53