1

I have below code for run a putty with authentication from C#

private void button1_Click(object sender, EventArgs e)
{

    ProcessStartInfo cmd = new ProcessStartInfo();
    cmd.FileName = "putty.exe";
    cmd.UseShellExecute = false;
    cmd.RedirectStandardInput = true;
    cmd.RedirectStandardOutput = true;
    cmd.Arguments = "-ssh " + username + host+ " -pw " + upassword;
    using (Process process = Process.Start(cmd))
    {         
        process.WaitForExit();         
    }
}

The above code is launching putty and authenticating the user and password. I want to execute some commands after launching the putty. I used below code

private void button1_Click(object sender, EventArgs e)
{

    ProcessStartInfo cmd = new ProcessStartInfo();
    cmd.FileName = "putty.exe";
    cmd.UseShellExecute = false;
    cmd.RedirectStandardInput = true;
    cmd.RedirectStandardOutput = true;
    cmd.Arguments = "-ssh " + username + host+ " -pw " + upassword+ "-m "+path;;
    using (Process process = Process.Start(cmd))
    {         
        process.WaitForExit();         
    }
}

The path variable contains the location of the file and file contain below text in it

ssh webhostname

While executing the above code, putty is launched but during authentication putty terminated with message "Unauthorized access to this machine is prohibited"

Is there anyway we can run the commands in putty from a file?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
vijil p
  • 11
  • 1
  • 1
    In your `cmd.Arguments` line, should there be an `@` between `username` and `host` ? – George Chen Aug 01 '18 at 14:35
  • 1
    Try adding a manifest file to your solution with requireAdministrator for execution level: https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator – christian Aug 01 '18 at 14:39
  • @Awakening Byte I am handling @ symbol when I am passing the hostname. I appended the @ symbol in hostname variable. – vijil p Aug 06 '18 at 12:21

0 Answers0