使用PROCESS.START()方法时C#:"登录失败:未知用户名或密码错误"错误

Ind*_*eti 0 .net wpf visual-studio-2010 c#-4.0

我尝试使用以下代码登录gmail:

private void button1_Click(object sender, EventArgs e)
{
    var user = new SecureString();
    foreach (char c in textBox3.Text)
    {
        user.AppendChar(c);
    }

    Process.Start("C:/Users/Indish/Desktop/chrome",
        "www.gmail.com", user, textBox4.Text);
}
Run Code Online (Sandbox Code Playgroud)

该程序说问题中提到的登录失败.所以,如果任何人可以帮助.........提前谢谢

Guf*_*ffa 5

首先,您正在使用错误的参数来重载您正在使用的方法.参数是:

Process.Start(fileName, userName, password, domain)
Run Code Online (Sandbox Code Playgroud)

因此,您将www.gmail.com作为用户名发送,并将用户名作为密码发送,这就是您收到登录失败的错误消息的原因.

您需要使用带有五个参数的重载来发送参数并登录到该方法:

Process.Start(fileName, arguments, userName, password, domain)
Run Code Online (Sandbox Code Playgroud)

但是,它用于为用于运行程序的用户帐户提供登录,而不是将登录信息发送到程序.

如果网页支持,您可以在URL中发送登录信息:

Process.Start("C:/Users/Indish/Desktop/chrome", user + ":" + textBox4.Text + "@www.gmail.com");
Run Code Online (Sandbox Code Playgroud)

否则,您需要在程序中嵌入浏览器控件,以便在加载后访问该表单.