Return Local Username

cyclonebri

Regular
Joined
Jul 30, 2003
Messages
93
Location
Ames, IA, USA
Hey everybody,

Just wondering how one would go about returning the username of the local profile being used as the application is running.

I know the system command -- %username% -- will return what I'm looking for in a command window or certain scripts, and was wondering if I could do this in an application. I am trying to get this information so I can write an xml settings file to the local user profile (the users have no rights on their machines and can only write to certain locations).

I want to open a file as follows:

[CS]
System.IO.StreamWriter myWriter = new System.IO.StreamWriter("C:\\Documents and Settings\\'%username'\\ ...");
[/CS]

Thanks in advance,
Brian
 
I have found the solution, in case anyone cares it is simply this:

[CS]
MessageBox.Show(System.Environment.UserName);
[/CS]

Obviously, one can leave off the MessageBox.Show, that was just to see it for testing purposes.

Thanks,
Brian
 
Back
Top