Mike Maggy
Mike Maggy

Reputation: 103

Telnet from command line doesn't work

I want to open Telnet session from command line via .NET. This command works fine manually:

telnet towel.blinkenlights.nl

So i try to open it via .NET

Process process = new Process();
process.StartInfo.FileName = @"C:\windows\system32\cmd.exe";
process.StartInfo.Arguments = "telnet towel.blinkenlights.nl";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();
process.WaitForExit();

I am using Wireshark to check if this start the traffic and here it seems that nothing happen and i cannot see any Telnet traffic.

Upvotes: 0

Views: 1550

Answers (1)

Andrew
Andrew

Reputation: 7880

If you use ProcessWindowStyle.Normal instead you would see you are not actually executing telnet. You must add the "/C" parameter if you want the CMD window to close after finishing or "/K" if you want it to remain open.

Process process = new Process();
process.StartInfo.FileName = @"C:\windows\system32\cmd.exe";
process.StartInfo.Arguments = "/k telnet towel.blinkenlights.nl";
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
process.WaitForExit();

After you get the behavior you want, then of course switch back to Hidden.

Upvotes: 1

Related Questions