Getting user name and extra info

dustintinsley

Member
Joined
Aug 23, 2006
Messages
8
Programming Experience
Beginner
For an application I am working on, need to get data from the "documents and settings/<user>/" directory. How would I got about getting the needed info for getting this directory? By this I mean how could I get the user name and the drive letter (incase windows isn't installed to the c: drive).
 
Since you are in .NET 2.0 and VS 2005 you could use the 'My' namespace that provides useful information.

Specifically:
VB.NET:
        My.Computer.FileSystem.SpecialDirectories.MyDocuments 'The MyDocuments will return a string of where the My Documents path is for the current logged in user.
        My.Computer.Registry.Users 'This is more of a registry value you might not need it.
        My.User.Name 'Returns the current logged in username.

       MsgBox(Environ$("windir")) 'Returns where Windows are installed on this computer.

You then use a DirectoryInfo class to retrieve file names, sizes and other functions.

Edit: You can also you the System.Environment namespace for same results.
 
Last edited:
Back
Top