0

I have a vb.net application that runs cmd.exe as the following:

Dim Port1 = CreateObject("WScript.Shell")
    Port1.Run("cmd.exe")
    Port1.Sendkeys("telnet ip address")
    Port1.Sendkeys("{Enter}")
    System.Threading.Thread.Sleep(6000)

When the cmd runs the sendkeys a error shows

"'telnet' is not recognized as an internal or external command, operable program or batch file."

I closed the cmd window, opened another cmd, and typed in the command with not problems.

I need cmd to run in the vb.net and not as a separate file.

Running the vb.net in Microsoft visual studio Ultimate 2013.

Update: Can anyone tell me why it is doing the same thing when i move the app to another computer and try to run it?

Alenhj
  • 109
  • 1
  • 2
  • 12
  • check this SO answer http://stackoverflow.com/questions/13807429/running-cmd-commands-with-administrator-rights – Mitz Jan 08 '15 at 19:03
  • 3
    My crystal ball says that you are running the 32-bit version of cmd.exe. Project + Properties, Compile tab. Change the Target CPU setting to AnyCPU and untick the "Prefer 32-bit" option. – Hans Passant Jan 08 '15 at 19:05
  • @HansPassant Your crystal ball can see far. I thank you for you help. – Alenhj Jan 08 '15 at 19:13

3 Answers3

1

You have to enable telnet on the computer by going to start > control panel > programs and features > turn windows feature on or off > check telnet client or typing optionalfeatures in run and checking telnet client. The command should execute successfully after that.

Ntellect13
  • 331
  • 1
  • 5
0

Either Telnet is not installed on your computer (it's not installed by default on any modern Windows versions as far as I know), or it its installation directory not in the PATH environment variable.

Either add it's install directory to PATH, or specify the full path to telnet.exe in the arguments to cmd.exe.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
-1

CMD runs commands based off of System32 and .bat(batch) or .exe. You would have to create a .exe or a .bat and place it into System32 in order for the command to work.