如何知道用户启动程序?

时间:2015-10-23 12:14:31

标签: c# process

我编写简单程序,从用户启动另一个Client.exe:

        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);
        }

它有效!但Client.exe如何知道用户执行此程序的内容?

1 个答案:

答案 0 :(得分:1)

您可以使用Environment类来了解这一点:

Environment.UserName

  

获取当前登录Windows操作系统的人员的用户名。

Environment.UserDomainName

  

获取与当前用户关联的网络域名。