Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:31:47+00:00 2026-06-01T21:31:47+00:00

Due to an architecture I must work with that likely breaks a lot of

  • 0

Due to an architecture I must work with that likely breaks a lot of very good software design rules, I need to send a message from some javascript code running in a web browser to a windows batch file on the same machine. The operating systems is Windows Vista or later. The browsers being used are primarily Chrome and Firefox. jQuery is also being used with the javascript.

The browser is connected to the internet and their is a server involved, so I could relay the message to the server, and then to the batch file. Right now I have a batch file that runs every minute or so that could theoretically query the server for any messages. Other than that, I don’t have any good ideas.

Additionally, this is a “closed” system. The client browser, client system, and server are under my complete control. It is not a situation where the general public is running the Javascript in their browser. The the client computer can be manipulated to be able to receive the message.

What is a good way to send this message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:31:47+00:00Added an answer on June 1, 2026 at 9:31 pm

    1. Local HTTP server

    From JavaScript, send AJAX request containing your command to local HTTP server. All modern browsers support cross-domain AJAX. The server can pass command as a parameter to the batch file. Make sure that the server is not accessible from network.

    The advantage of this approach is that you can send response from command back to JavaScript.

    • JavaScript:

      $.post('http://localhost:8080', {command: '...'});
      
    • Bottle.py server:

      #!/usr/bin/python
      from bottle import run, route, request, response
      import subprocess
      
      @route('/', method='POST')
      def index():
          command = request.POST['command']
          result = subprocess.check_output(['batchfile.bat', command], shell=True)
      
          response.set_header('Access-Control-Allow-Origin', '*')
          return result
      
      run(host='localhost', port=8080, reloader=True)
      
    • Or PHP under Apache/nginx:

      $result = shell_exec("batchfile.bat " . escapeshellarg($_POST['command']));
      
    • Or daemon in PHP:

      For extra fun it has full shell access and can run commands asynchronously, which allows to launch desktop applications without blocking. It doesn’t need Apache.

      Start: php.exe -f batrunner_daemon.php

      Use: $.get('http://localhost:33333/ping -h', function(response) { console.log(response) });

      $host = '127.0.0.1';
      $port = 33333;
      $async = false; // enable to run commands without blocking the server (useful for GUI applications)
      
      $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
      $open = @socket_bind($socket, $host, $port);
      if ($open) {
          echo "\nListening on http://{$host}:{$port}";
      } else {
          echo "\nError. Port {$port} in use";
          exit;
      }
      socket_listen($socket, 1);
      
      while(1) {
          $connection = socket_accept($socket);
          $http_request = socket_read($connection, 32768);
          $command = rawurldecode(substr(strstr($http_request, "\r\n", true), 5, -9));
      
          echo "\nRunning: {$command}...";
      
          if ($async) {
              $response = pclose(popen('start "" /B ' . $command, 'r')) ? 'error' : 'success';
          } else {
              $response = shell_exec($command);
          }
      
          echo " Done.";
      
          socket_write($connection, implode("\r\n", array(
              'HTTP/1.1 200 OK',
              'Content-Type: text/plain; charset=UTF-8',
              'Connection: close',
              'Content-Length: ' . strlen($response),
              'Access-Control-Allow-Origin: *',
              "\r\n" . $response
          )));
          socket_close($connection);
      }
      

      To keep it simple, it doesn’t have proper error handling and allows any site to execute anything on your computer, use at your own risk.

      Access-Control-Allow-Origin: * means that any site can receive response from shell. Without this header they obviously still can run commands, but can’t receive response.


    2. URI Scheme

    I experimented with @mamdrood’s idea, and it turned out to be very simple, much easier than HTTP server.

    • From HTML, you’ll be able to call the batch file like this:

      <a href="batrunner://somecommand">Wipe all files</a>
      
    • And here’s how the batch file in C:\mybatfile.bat can parse commands:

      @echo off
      SET command=%1
      SET command=%command:batrunner://=%
      echo %command%
      

      I’m not very familiar with batch files, and my command name parsing code can be vulnerable. If you know any better please update this answer.

    • To associate your batch file with batrunner:// protocol create batrunner.reg and run it once. Substitute C:\\mybatfile.bat for your script, path should be escaped.

      Windows Registry Editor Version 5.00
      
      [HKEY_CLASSES_ROOT\batrunner]
      "URL Protocol"=""
      
      [HKEY_CLASSES_ROOT\batrunner\shell]
      
      [HKEY_CLASSES_ROOT\batrunner\shell\open]
      
      [HKEY_CLASSES_ROOT\batrunner\shell\open\command]
      @="C:\\mybatfile.bat %1"
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to politics at the very large finanial institution for which I work, I
Due to network architecture of our software, our application servers cannot connect directly to
I am reading a book on design patterns (an old edition) Pattern-oriented software architecture
Due to some rather bizarre architectural considerations I've had to set up something that
Due to legacy reasons a lot of our data is stored encoded in standard
Due to a number of constraints that I won't get into, I have to
I'm currently designing an architecture for a web-based application that should also provide some
I am designing the architecture for a set of WCF services. Due to the
I am using WiX to install a plugin for a software that I am
I am working within a enterprise architecture that is processing a large amount of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.