Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trying to call cmd.exe from JS

    I'm still kind of a noob to Javascript so I may be out of my league here but I'm trying to run a ping from a button through XML. I can't even get a command prompt to open much less run the ping

    Here is my function


    onToolbarpingerCommand: function(e) {

    var objShell = new ActiveXObject("Shell.Application");
    objShell.ShellExecute("cmd.exe", "ping" + "192.168.0.1");
    }


    I'm still learning so please don't write all the code for me. (unless it is an easy mistake :P ) I'm simply looking for guidance on what I'm doing wrong.

  • #2
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have been searching around and also found it done like this.


    onToolbarpingerCommand: function(e) {

    var run=new ActiveXObject('WSCRIPT.Shell').Run("cmd.exe", "ping" + "192.168.0.1");
    }


    Has about the same amount of functionality for me though

  • #3
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    I haven't played with your code but three obvious things:

    it will only work in IE
    you need a space after "ping"
    are you calling the function?
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #4
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply

    Sorry as I said I'm fairly new Why would it only work in IE? Bad part is that this is a part of a firefox extension . That could be my whole issue.

    The space for the ping I thought would be in place due to the double quotes. Either way I cannot even get the prompt to open for the ping to be placed.

    I am calling the function with a button in XUL as outlined below


    <toolbarbutton id="customer_direct_helper-toolbar-pinger"
    tooltiptext="&customer_direct_helperToolbarpinger.tooltip;"
    label="&customer_direct_helperToolbarpinger.label;" oncommand="customer_direct_helper.onToolbarpingerCommand()" />

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    objShell.ShellExecute("cmd.exe", "ping 192.168.0.1");
    .. but ActiveXObject is an IE-only object.

    I am unable to advise further, sorry

    Added: Is ping useful anyway, if you are unable to check its response..

    Pingler
    Last edited by AndrewGSW; 11-14-2012 at 10:51 AM.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,380
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Code:
    function ping(ip) {
    	clearTimeout(ping.timer);
    	var i = ping.i || (ping.i = new Image);
    	i.src = "http://"+url;
    	ping.timer = setTimeout(function() {
    		i.src = "";
    	}, 9999 );
    } /* end ping() */
    usage:
    Code:
    ping ("192.168.0.1")
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    @rnd me: Thank you.

    A little search tells me that ping-ing notifies a server of changes to a web page (or site).

    This seems (to me) to be almost accidental, as it's original purpose - from the command line - was to test a connection, receiving a detailed response. I gather that the response itself is usually ignored, as simply receiving any response is sufficient to confirm the connection as 'active'.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,380
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by AndrewGSW View Post
    @rnd me: Thank you.

    A little search tells me that ping-ing notifies a server of changes to a web page (or site).

    This seems (to me) to be almost accidental, as it's original purpose - from the command line - was to test a connection, receiving a detailed response. I gather that the response itself is usually ignored, as simply receiving any response is sufficient to confirm the connection as 'active'.
    no, this simply tries to load the front page of the IP address, regardless of if it changed or not. you won't get any feedback in js with the above script, though the site can feel it.

    if the site is not one you control, it's more difficult to tell exactly what's going on with its content, or even if it's online.

    one "hack" is using a known image url to see if the site is online. you load an image at the url and wait to see if the load() or error() fires. if error() fires, the server is offline.

    if the server emits access-control headers, you can use ajax to fetch the url and inspect the content for changes yourself.


    finally, it is VERY practical and possible to use "timing attacks" and error messages to determine if a site is on or offline. various incarnations of this use hidden iframe load events, img ping timeouts, and certain subtle differences in some javascript-reported URL-based error messages between status 200, 404, and no response at all. i won't go into details here, but the info is out there if you need it.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •