none
getting current user name RRS feed

  • Question

  • how can i get the name of the current user - is it in the registry? is there a function?

    i want to do this in case i want to put something on the desktop or in my documents ect.

    thanks in advance

    Friday, March 23, 2007 11:35 PM

Answers

  • try this...

    The attached source code returns the system information for your machine such as machine name, operating system, current user and logical drives.

    //Gives the Directory which is using by ur system
    lbl13.Text=Environment.CurrentDirectory;
    //Shows u the system Directory
    lbl12.Text=Environment.SystemDirectory;
    //show the version of the system
    lbl11.Text=Convert.ToString(Environment.Version);
    lbl10.Text=Convert.ToString(Environment.OSVersion);
    //Shows the Machine Name
    lbl9.Text=Environment.MachineName;
    lbl8.Text=Convert.ToString(Environment.WorkingSet);
    //Command Line Arguments
    string [] args=Environment.GetCommandLineArgs();
    for (int x=0;x<args.Length;x++)
    {
    MessageBox.Show(args[x],"Command Line Arguments",MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,MessageBoxOptions.ServiceNotification);
    }
    //Logical Drives
    string []drives=Environment.GetLogicalDrives();
    for(int x=0;x<drives.Length;x++)
    {
    MessageBox.Show(drives[x],"LogicalDrives",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    // Display the Current User Name
    MessageBox.Show(Environment.UserName,"Current User Name",MessageBoxButtons.OK,MessageBoxIcon.Information);
    lbl16.Text=Environment.StackTrace;
    //Shows the Domain name of the system
    lbl18.Text=Environment.UserDomainName;

    Saturday, March 24, 2007 3:20 AM
  •  

    // username.cpp
    // compile with: /clr
    using namespace System;
    
    int main() 
    {
       Console::WriteLine("\nCurrent user: {0}", Environment::UserName);
       return 0;
    }
     
    if u find both these answers right n helpful plz mark them answers.
    Saturday, March 24, 2007 3:25 AM
  • The SDK has the GetUserName function.
    Saturday, March 24, 2007 7:03 AM
  • Hello

     

    Re question:

     

    Such questions are outside the scope of this forum - for the scope of the VC General forum please look at: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=19445&SiteID=1

     

    The more appropriate place for your question is probably one of the Win32 newsgroups: http://msdn.microsoft.com/newsgroups/topic.aspx?url=/MSDN-FILES/028/201/015/topic.xml

     

    OTP

     

    Thanks

    Damien

    Monday, March 26, 2007 11:16 PM
    Moderator

All replies

  • try this...

    The attached source code returns the system information for your machine such as machine name, operating system, current user and logical drives.

    //Gives the Directory which is using by ur system
    lbl13.Text=Environment.CurrentDirectory;
    //Shows u the system Directory
    lbl12.Text=Environment.SystemDirectory;
    //show the version of the system
    lbl11.Text=Convert.ToString(Environment.Version);
    lbl10.Text=Convert.ToString(Environment.OSVersion);
    //Shows the Machine Name
    lbl9.Text=Environment.MachineName;
    lbl8.Text=Convert.ToString(Environment.WorkingSet);
    //Command Line Arguments
    string [] args=Environment.GetCommandLineArgs();
    for (int x=0;x<args.Length;x++)
    {
    MessageBox.Show(args[x],"Command Line Arguments",MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,MessageBoxOptions.ServiceNotification);
    }
    //Logical Drives
    string []drives=Environment.GetLogicalDrives();
    for(int x=0;x<drives.Length;x++)
    {
    MessageBox.Show(drives[x],"LogicalDrives",MessageBoxButtons.OK,MessageBoxIcon.Information);
    }
    // Display the Current User Name
    MessageBox.Show(Environment.UserName,"Current User Name",MessageBoxButtons.OK,MessageBoxIcon.Information);
    lbl16.Text=Environment.StackTrace;
    //Shows the Domain name of the system
    lbl18.Text=Environment.UserDomainName;

    Saturday, March 24, 2007 3:20 AM
  •  

    // username.cpp
    // compile with: /clr
    using namespace System;
    
    int main() 
    {
       Console::WriteLine("\nCurrent user: {0}", Environment::UserName);
       return 0;
    }
     
    if u find both these answers right n helpful plz mark them answers.
    Saturday, March 24, 2007 3:25 AM
  • The SDK has the GetUserName function.
    Saturday, March 24, 2007 7:03 AM
  • Hello

     

    Re question:

     

    Such questions are outside the scope of this forum - for the scope of the VC General forum please look at: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=19445&SiteID=1

     

    The more appropriate place for your question is probably one of the Win32 newsgroups: http://msdn.microsoft.com/newsgroups/topic.aspx?url=/MSDN-FILES/028/201/015/topic.xml

     

    OTP

     

    Thanks

    Damien

    Monday, March 26, 2007 11:16 PM
    Moderator
  • yet another idea is to read from environment variable 'USERNAME'
    Tuesday, March 27, 2007 10:10 AM