Chrome sendNativeMessage with Batch, CMD or PowerShell - google-chrome-app

Google provides an example of calling native executables here. The actual "executable" is a .BAT file which calls python. I wanted to see if I could just run a .bat file with some typical OS or maybe even PowerShell commands. According to the help the executable needs to return UTF-8 JSON so I replaced the call to python with the following command:
TYPE %~dp0\SAMPLE.json
Where SAMPLE.json is a UTF-8 file with some JSON content.
Needless to say it does not work:
Error when communicating with the native messaging host.
According to the help it could be because of message size or text vs. binary output modes. I know of no way to get a batch file to "talk binary".
Is there any way to get Chrome to talk to text based CLI utilities like batch files, powershell...?

Related

How to Automate scripts with options in Powershell?

I'm not a native English speaker as such pardon some discrepancy in my question. I'm looking at a way to Automate option selection in Programs/Scripts running via PowerShell.
For example:
Start-Process -FilePath "velociraptor.exe" -ArgumentList "config generate -i"
In the above snipper PowerShell will run Velociraptor and initiate the configuration wizard from a Ps1 file. The Wizard has few options. After running it will generate some Yaml files.
As such what would be the way to have PowerShell Script automate the option selection process? I know what the option should be. I looked around but I don't know proper terms to find what I need. Nor am I sure this can be done with PowerShell.
The end goal is to have the Ps1 download Exe, run the config command and continue with choosing the selection based on predefined choices. So far I gotten download and lunching of the velociraptor.exe working. But not sure how to skip the window in screenshot and have PowerShell script do it instead.
I couldn't find a CLI reference for velociraptor at https://www.velocidex.com/, but, generally speaking, your best bet is to find a non-interactive way to provide the information of interest, via dedicated _parameters_ (possibly pointing to an input file).
Absent that, you can use the following technique to provide successive responses to an external program's interactive prompts, assuming that the program reads the responses from stdin (the standard input stream):
$responses = 'windows', 'foo', 'bar' # List all responses here
$responses | velociraptor.exe config generate -i

Opening a file in a Metro app from command line

I need a way to open a file in a Metro app from command line.
So far I've figured out how to start the app from command line without any third-party scripts
explorer shell:AppsFolder\Microsoft.Reader_8wekyb3d8bbwe!Microsoft.Reader
but I haven't been able to figure out how to include a file name yet.
Launching
explorer shell:AppsFolder\Microsoft.Reader_8wekyb3d8bbwe!Microsoft.Reader example.pdf
just opens up a default explorer window.
Any idea from Windows 8 experts on how to accomplish this without any third-party tools/cmdlets/etc.?
Note: In fact I'm using Windows 10 but I guess if there's a Windows 8 / 8.1 way to do it, it'll work for 10, too.
If you're still looking for the answer, the best way to open a file in a metro app is to use an execution string like a normal app protocol does. The execution string looks like this:
bingnews:[arguments, can be left blank.]
microsoftvideo:[arguments, can be left blank.]
netflix:[arguments, can be left blank.]
So, to start up netflix, it's as simple as typing in Start netflix: into the command line.
To find the execution string for an app, go here: Control Panel\Programs\Default Programs\Set Associations
More info and examples can be found here.
http://windowsitpro.com/windows-8/opening-windows-8-apps-command-prompt-or-script
http://www.itsjustwhatever.com/2012/10/28/launch-windows-8-metro-apps-from-a-desktop-shortcut-or-command-line/
PLEASE NOTE: To open an app WITHOUT A PROTOCOL (One not listed in the registry or under "Set Associations") use OP's method:
explorer shell:AppsFolder\[appuid]![appfullname]
The app UID is the folder name without the version number. For example,
4DF9E0F8.Netflix_2.11.0.8_x64__mcm4njqhnhss8
becomes
4DF9E0F8.Netflix_mcm4njqhnhss8
The app fullname is the [App author].[App name] For example, 4DF9E0F8.Netflix. 4DF9E0F8 is the author, and Netflix is the name.
Put it all together to get
explorer shell:AppsFolder\4DF9E0F8.Netflix_mcm4njqhnhss8!4DF9E0F8.Netflix
Store Apps can only be started by the shell. So try this:
explorer.exe shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
Or from run (Win+R):
shell:AppsFolder\Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
If the app is the default handler then you can just launch the file or protocol. There isn't a good in-box way to launch a file into a non-default handler from the command line.
Windows Store apps aren't designed to run from the command line and there isn't a straightforward way to launch them from the command line. Apps which handle specific files or protocols receive them through FileActivatedEventArgs or ProtocolActivatedEventArgs rather than command line arguments
You could write a launcher app which uses CLSID_ApplicationActivationManager's IApplicationActivationManager to ActivateForFile a specific app.
The best way I've found to pass command-line arguments to the executable targeted by the shell command is via the Windows start command.
Using your example, you would end up with this:
start "" shell:AppsFolder\Microsoft.Reader_8wekyb3d8bbwe!Microsoft.Reader example.pdf
I don't have Microsoft.Reader installed, so I can't test that. However, I can verify that this pattern works with Windows Terminal. In this case, I pass it a command-line argument to tell it which profile I want to open.
start "" shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App new-tab -p "GitBash"
The first argument to the start command here — the empty string — is just the title of the window.
You can also pair this with cmd /c, which I've found is necessary for some launcher applications, such as my personal favorite, SlickRun:
cmd /c start "" shell:AppsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App new-tab -p "GitBash"
I have a blog post with more info on running Modern apps from the command line, which you might find helpful in constructing these ridiculously obtuse commands.
Not sure if it works on Windows 8, but on Windows 10 I use this:
cmd /C start <app-name>:
For example, to start Slack:
cmd /C start slack:

Making bat file in Window Mobile 6

I have Windows mobile 6. I have installed Cre-ME+, and command line. In the command line we need to type the following command and execute it, to load Oracle Mobile Application:
\Windows\CrEme\bin\CrEme.exe -Of -classpath \Windows\CrEme\lib\AWTclasses.zip;\XONTMWA\lib\j4205328.zip oracle.apps.mwa.awt.client.StartGUI
However, Windows Mobile does not support the bat/cmd file execution, so what would be a equivalent way of starting the Oracle Mobile Application, without having to type the command every time?
Create a shortcut with the command line, either via API or with your favorite text editor.
The contents would look like this (if my character count is right anyway):
139#\Windows\CrEme\bin\CrEme.exe -Of -classpath \Windows\CrEme\lib\AWTclasses.zip;\XONTMWA\lib\j4205328.zip oracle.apps.mwa.awt.client.StartGUI

How do you make a MSDOS .com file?

How do you make a .com file for MS-DOS? I have my own "operating system", PowerOS, and I want custom commands to be able to be entered. Is there any way to write a .com file?
The answer is fairly straightforward. You make a .COM file containing an MS/PC/DR-DOS program image by writing a program in a programming language and compiling it with a compiler that targets MS/PC/DR-DOS. That's it.
Don't get confused about filename extensions. There's a .COM program image file format, which is a fairly basic program image format. It was superseded by the "MZ" program image file format back in the 1980s. But it has nothing to do with the filename extension. A program image file for MS/PC/DR-DOS can have either the extension .COM or the extension .EXE, but the actual image file format is not dictated by this. (I mention DR-DOS. If memory serves correctly: In DR-DOS version 6 practically all of the program image files, even the ones named .COM, were actually "MZ" format executables, and compressed ones at that.)
What you do depends from what program image file formats your operating system's program loader is capable of understanding. And, really, only you can tell the world that. If your operating system's program loader understands the "MZ" executable file format, and the programs that run on your operating system are 16-bit and run in real mode, then compiling commands for your operating system is as simple (ignoring system call and library issues) as, say, cranking up OpenWatcom's 16-bit compiler+linker, wcl, and telling it to target MS/PC/DR-DOS with the -bcl=DOS option.
Of course, if your programs are 32-bit and your operating system runs them in protected mode, or even if your programs are 16-bit and your operating system runs them in protected mode, then the "MZ" file format will be unsuitable for your needs, and you should use one of the several alternative program image file formats.
I know that for windows 7 and most likely for the other windows OS's you can write either a .bat, .exe, or .com and place it into windows/system32 folder. That file can be used as a command from the command prompt by simply typing in the name of the command you made.
To take in command line parameters, a batch file can use the variables %1, %2, %3 etc. The command works like any other command and can be used to further write batch files with it.
As far as MS-DOS goes, you may be able to place one of those file types in the root directory or find where the other commands are placed and put it there. I am not sure if a COM file is required, but if so, there are batch to com converters out there such as this old school one:
Converter from batch to com
you can make an .bat file and paste this code to make custom commands
example:
#echo off
set /p command=
if %command% ==
in the code type your command at the end and what you will the command to do.
you can copy the if command to ad more commands

How can I communicate with an application that does not return to the command prompt?

I need to build a test bench by sending appropriate inputs to an application. However,
once I launch the application, it takes control and does not return to the command
prompt (unless an exit command is executed from the application). In that case
is there any technique by which I can send a command to that application from the Perl
script and interpret the output from that application?
My operating system is Windows.
If it's a GUI application, take a look at the Win32::GuiTest module. It sends events to GUI applications - simulating user input.
For a command line application, I would normally recommend the Expect module. Unfortunately, Expect doesn't work under Windows.
If there is anyway to write or redirect the application output to a file, you can always open that file to process/interpret the output. If you are talking about a command-line application, it should be easy to redirect the terminal output to a file using the '>' and '>>' characters. It may not be as easy with a GUI app, though.