[NWjs] Run *.bat or cmd from path

Get help using Construct 2

Post » Sat Sep 10, 2016 4:00 pm

Hi community!

First off: this question isnt part of a game - Im playing arround with C2. I want to extend a console-automation I wrote for my company with a GUI (since making a GUI in PowerShell is a pain in the a.... without tools from SAPIEN or others...).

I tryed a whole lot in making NWjs to open a *.bat or command prompt window. I can't figure out how to do that. :geek:

Something of what I tried so far:
- NWjs | Run "C:\Temp\my_bat_file.bat" // nope
- NWjs | Run "C:\Windows\system32\cmd.exe" // nope
- NWjs | Run "C:\Windows\SysWOW64\cmd.exe" // nope
- NWjs | Run "cmd.exe" // nope
- NWjs | Run "process.env.ComSpec + ' /c batfile.bat" // nope (whyever I thought that may works - found that while searching on Google - and yes, I pasted node.js code here... :roll: )

Since launching a *.exe works fine just as it should, I downloaded a bat2exe complier and compiled my *.bat into an executable:
- NWjs | Run "C:\Temp\my_bat_file.exe" // also: nope
[everything else what I tried doesnt really made sense at all...]

My batch just pings Google (8.8.8.8) so far - nothing special. I do not need any kind of automation/value-returning - the user should just see the opened command prompt window with its contents shown before a "pause"- interaction.

I thought about security reasons why it isnt possible - but writing a malicious script in VS/vbs and compiling it into a native executable is just as easy as in a simple batch script - so I dont think that someone restricted that because of security reasons (obviously I do not want to write malicious software nor harm any system - just to have it said at this point!).

Does someone know a work-arround for simply opening a *.bat - or if not otherwise possible a compiled *.exe from a *.bat script?

Have a great weekend
Proxy


Edit: even the fail-safe method: NWjs Open Dialog, choosing file, Run NWjs.ChosenPath - doesnt work... I think this has nothing to do with a wrong path or such...
B
24
S
14
G
9
Posts: 118
Reputation: 6,799

Post » Sat Sep 10, 2016 7:10 pm

I hope this will work for you (I've not tried it). NWjs spawning .bat and .cmd

Edit:

If you include the .bat file inside the package.nw (ie import it into c2) then use:

Code: Select all
require('child_process').exec('cmd /c batfile.bat', function(){
   // …your callback code may run here…
});
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,208
Reputation: 43,838

Post » Sat Sep 10, 2016 7:38 pm

Colludium wrote:I hope this will work for you (I've not tried it). NWjs spawning .bat and .cmd

Edit:

If you include the .bat file inside the package.nw (ie import it into c2) then use:

Code: Select all
require('child_process').exec('cmd /c batfile.bat', function(){
   // …your callback code may run here…
});


Thanks, Colludium!

Already took a look at that Wiki entry - but I hoped to realize that without modifing anything. ;)

I could also use ajax to realize that, but the main problem is, that I do not want to add anything into the C2 project. When starting the script/app you are prompted for 2 *.csv files, one contains software (vendor,name,path-to-exe, etc.) and one contains a collection of batch-files. The reason why Im doing it that way: not every machine has the same software and/or "functions/features" installed - because of that, you ll have multiple "Softwareconfiguration.csv"s and "Functionconfiguration.csv"s. Plus: when a new software is added to the system, you only have to add a row in one of the *.csv file; same with the "function" configuration. Its aimed to be multiusable without even thouching the C2 projectfiles... (you may know the wise words: "lazy admin is best admin" :D ).

So all in all I want to compile the C2 project a single time and want to be able to extend the functionality anytime just by editing *.csv files (and last but not least, editing a *.csv file is much more easier for my collegues instead of opening C2 and editing something in the project itself (and of course, I own the license by myself, not in/for the company ;) ).

But well, if there isnt an another way, I have to mod the plugin.

Thanks, anyway! :)

Have a great weekend!
Proxy
B
24
S
14
G
9
Posts: 118
Reputation: 6,799

Post » Sat Sep 10, 2016 8:28 pm

Try:

NWjs | Run "start" for a CMD and
NWjs | Run "start pathToBatFile" for a batch-file

for example:
NWjs | Run "start c:\mybat\batch.bat"
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Sat Sep 10, 2016 8:57 pm

Asmodean wrote:Try:

NWjs | Run "start" for a CMD and
NWjs | Run "start pathToBatFile" for a batch-file

for example:
NWjs | Run "start c:\mybat\batch.bat"


You, sir, are a hero! :mrgreen:

Thanks! Works totally fine.

Run file
Run the file at an existing file path. This is analogous to double-clicking the file in the OS file explorer. For executable programs, it will attempt to run the program; for other file types, it will open the default associated program, such as the system default image editor if an image file is given.
@ https://www.scirra.com/manual/search?q=nwjs

Would be worth mentioning there @Ashley ;D

Have a great weekend
Proxy
B
24
S
14
G
9
Posts: 118
Reputation: 6,799

Post » Wed Jan 11, 2017 11:22 am

Asmodean wrote:Try:

NWjs | Run "start" for a CMD and
NWjs | Run "start pathToBatFile" for a batch-file

for example:
NWjs | Run "start c:\mybat\batch.bat"


This worked for me too, except when there are spaces in the file path, "c:\first folder\second folder\...". Somewhere I read that we should use double quotes (run | "start" """c:\first folder\..."""), but I haven't been able to make it work.

Any ideas?
B
17
S
2
Posts: 88
Reputation: 1,503

Post » Wed Jan 11, 2017 12:25 pm

Try
NWjs | Run "start c:\""first folder\second folder""\batch.bat"

or with a folder in between without space

NWjs | Run "start c:\""first folder""\folder\""second folder""\batch.bat"
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Thu Jan 12, 2017 5:35 pm

Is this dangerous? Or is nw.js the desktop publisher?
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,415
Reputation: 4,824

Post » Tue Sep 19, 2017 3:26 pm

Is it possible to use a path from an edit box / variable? can't seem to get the run command to work with a folder value the user chooses, which gets stored in an edit box and written to an ini file. :|
B
38
S
8
G
5
Posts: 143
Reputation: 4,634

Post » Tue Sep 19, 2017 3:31 pm

Ah got it working... did """"&editboxname.text&""""" (four speech quotes either side) :)
B
38
S
8
G
5
Posts: 143
Reputation: 4,634


Return to How do I....?

Who is online

Users browsing this forum: evillair, lordsas, Matei511, tarek2 and 62 guests