Jaideep Bahadur Srivastava Jaideep Bahadur Srivastava - 1 month ago 19
Javascript Question

Batch file not prompting for user input when triggered using chrome native messaging

I am working on a Chrome extension Extension and using Native messaging for invoking Ping.exe. Since I need to choose IP's at runtime, I was thinking of having a batch file which can prompt user for entering IP's.It works fine, if i directly click on the batch file and get proper response after prompting for input.But when I try to invoke it through a UI i have created, using Native messaging it does not prompt user and directly invoke the exe with the default IP set.What wrong i am doing here ?

Thanks in advance.


batch File -

@echo off
set id=
set /p id= Enter IP:
set Pathname="C:\Windows\System32"
cd /d %Pathname%
start call PING.exe %id%

JS -

'click', connect);

function connect() {

var hostName = "com.google.chrome.example.echo";
port = chrome.runtime.connectNative(hostName8);

Manifest --

"name": "com.google.chrome.example.echo",
"description": "My Application",
"path": "C:\\Extension\\ping.bat",
"type": "stdio",
"allowed_origins": [



That's because your UI creates the process without a valid standard input or a redirected standard input.

When interactive set tries to scan the input, it gets "end of file", and keeps the default, previously set value.

I can propose you an even better alternative, since it's graphical:

1) create a .vbs script (in the same directory as your batch file) that prompts for an address and prints it to stdout:

SET FS = CreateObject("Scripting.FileSystemObject")
SET StdOut = FS.GetStandardStream(1)
StdOut.Write(InputBox("IP Address"))

2) in your batch script do this:

cscript /nologo %~pd0\ipprompt.vbs > %TEMP%\ipaddr.txt
set /p id=<%TEMP%\ipaddr.txt

A VB window will appear prompting you for IP address, and echoes it, redirected to a file. Put that back in your id env. variable and you're done, without using standard input at all.