6

I am trying to open a telnet window and send some keys to this active window. Below is the JavaScript code:

var oWshShell = new ActiveXObject("WScript.Shell");
oWshShell.Run("telnet 43.43.22.45 23");
//oWshShell.Run("firefox.exe http://www.google.com");
//oWshShell.Run(" notepad.exe");
oWshShell = null;

But I am unable to open them all the same. It says the file does not exist. However, the commented lines work perfectly, when uncommented. what could be the problem?

Thanks in advance.

nmagerko
  • 6,586
  • 12
  • 46
  • 71
Avi
  • 368
  • 2
  • 13
  • 1
    how can we have the ActiveXObject("WScript.Shell") method in firefox. the above code works only in IE. – Avi May 01 '12 at 12:16
  • Maybe you need to have ".exe", like "telnet.exe ..." and not just telnet – Christian V May 01 '12 at 12:18
  • i tried that..it does not works, i even gave the full path to the exe – Avi May 01 '12 at 12:22
  • Why are you writing this in JavaScript? This looks very much like a windows batch/cmd file. Where (console window, browser, etc.) and how (the details of how you trigger running of the script) are you running this code? – Sean Mickey May 02 '12 at 04:00
  • bcos i want this to be executed when my page loads. The triggering point will a call to this function on any button click. – Avi May 04 '12 at 10:08

3 Answers3

1

@Avi, I dont't think you'll be able to execute this type of command when a page loads unless you use Internet Explorer and enable full trust security. If you must do this way, though, you just have to specify the full path to telnet.exe. Just beware that windows uses \ to separate the directory levels, but this is a special character to javascript, and it must be escaped; i.e:

var path = "c:\\Windows\\System32"; // this is c:\Windows\System32 in javascript
Gerardo Lima
  • 6,467
  • 3
  • 31
  • 47
0

Have you tried using a URL like telnet://43.43.22.45 instead?

<a href="telnet://43.43.22.45">Connect to server</a>.
Asherah
  • 18,948
  • 5
  • 53
  • 72
0
oWshShell.Run("telnet 43.43.22.45 23");

Telnet is in the system path by default. So this should work.

//oWshShell.Run("firefox.exe http://www.google.com");

Firefox is not in the system path. Therefor, run has no idea how to find it.

//oWshShell.Run(" notepad.exe");

Note the space before " notepad" --> That file name doesn't exist.

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74