0

I write simple program, that starts another Client.exe from user:

        Console.Write("Enter your domain: ");
        string domain = Console.ReadLine();
        Console.Write("Enter you user name: ");
        string uname = Console.ReadLine();
        Console.Write("Enter your password: ");
        SecureString password = new SecureString();
        ConsoleKeyInfo key;
        do
        {
            key = Console.ReadKey(true);

            // Ignore any key out of range.
            if (((int)key.Key) >= 33 && ((int)key.Key <= 90) && key.Key != ConsoleKey.Enter)
            {
                // Append the character to the password.
                password.AppendChar(key.KeyChar);
                Console.Write("*");
            }
            // Exit if Enter key is pressed.
        } while (key.Key != ConsoleKey.Enter);
        Console.WriteLine();

        try
        {
            Console.WriteLine("\nTrying to launch ProcessClient using your login information...");
            Process.Start("ProcessClient.exe", uname, password, domain);
        }
        catch (Win32Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

And it works! But how Client.exe knows what user execute this program?

Mukesh Kalgude
  • 4,814
  • 2
  • 17
  • 32
Admiral Land
  • 2,304
  • 7
  • 43
  • 81
  • this one probably? http://stackoverflow.com/questions/1240373/how-do-i-get-the-current-username-in-net-using-c – M.kazem Akhgary Oct 23 '15 at 12:17
  • 1
    Possible duplicate of [Determine from within code which user my process is running as](http://stackoverflow.com/questions/4260701/determine-from-within-code-which-user-my-process-is-running-as) – Alex K. Oct 23 '15 at 12:22
  • What piece of the user's information do you want to get, exactly? You already have the username... What do you actually want? – Rob Oct 23 '15 at 12:26

1 Answers1

1

You can know this using the Environment class:

Environment.UserName

Gets the user name of the person who is currently logged on to the Windows operating system.

Environment.UserDomainName

Gets the network domain name associated with the current user.

Community
  • 1
  • 1
Nasreddine
  • 36,610
  • 17
  • 75
  • 94