Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have used C# for a few years now under Windows Vista but currently started dual-booting Ubuntu 11.10. I Understand the concept of finding the current User in Windows which is
C#
string user = System.Environment.UserName

I am currently using Mono Develop, I have tried Google until I was more confused than when I originally started. If someone has any idea's or suggestions that could help me out further. The code that I currently Use looks like this but I'm sure there has to be a better solution.
C#
  private static class Users     	
  {	
      public static string Current()
      {				
       string[] PathParts = Application.StartupPath.Split('/');					
       if(PathParts.Length <= 2 || !Environment.OS.IsUnix())
       {						
	  return null;
       }	
	  return PathParts[2];
       }
    }
<pre lang="c#">
Posted

1 solution

I think correct way to get the User Name using
System.Security.Principal.WindowsIdentity.GetCurrent().Name


It gives, user name application running as user.
 
Share this answer
 
Comments
charles henington 20-Jul-12 17:26pm    
And that would be correct my 5 and thanks for the reply
Parwej Ahamad 21-Jul-12 0:34am    
Thanks Charles!

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