Skip to content

Commit 20677a1

Browse files
committed
possibility to package HTA files instead of Batch
1 parent 08dded8 commit 20677a1

File tree

7 files changed

+71
-30
lines changed

7 files changed

+71
-30
lines changed
File renamed without changes.
File renamed without changes.

hta/js/process.js renamed to hta/process.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
window.resizeTo(350,490);
21
var fso = new ActiveXObject('Scripting.FileSystemObject');
32

43
function sendToBatch() {
54
var form = document.forms[0];
6-
var batfile = form.elements['batfile'].value;
5+
var srcfile = form.elements['srcfile'].value;
76
var include = form.elements['include'].checked;
87
var hidcon = form.elements['hidcon'].checked;
98
var completion = form.elements['completion'].checked;
109
var distname = form.elements['distname'].value;
1110
var icon = form.elements['icon'].value || false;
12-
if (icon && !hasExtension(icon, 'ico')) return false;
13-
if (isRequired(batfile) && hasExtension(batfile, 'bat') && isRequired(distname) && isWinFilename(distname)) {
14-
var src = splitPath(batfile);
11+
if (icon && !hasExtension(icon, ['ico'], true)) return false;
12+
if (isRequired(srcfile) && hasExtension(srcfile, ['bat', 'hta'], true) && isRequired(distname) && isWinFilename(distname)) {
13+
var src = splitPath(srcfile);
1514
var output = src.folder +'~'+ src.file +'~'+ include +'~'+ hidcon +'~'+ completion +'~'+ distname +'~'+ icon;
1615
if (!checkOverwrite(distname, src.folder)) return false;
1716
fso.GetStandardStream(1).Write(output);
@@ -23,7 +22,8 @@ function changeCompletion() {
2322
var form = document.forms[0];
2423
var completion = form.elements['completion'];
2524
var hidcon = form.elements['hidcon'];
26-
if (hidcon.checked) {
25+
var srcfile = form.elements['srcfile'].value;
26+
if (hidcon.checked && hasExtension(srcfile, ['bat'], false)) {
2727
completion.disabled = false;
2828
removeClass(completion.parentNode, 'text-muted');
2929
} else {
@@ -35,9 +35,9 @@ function changeCompletion() {
3535

3636
function changeDistname() {
3737
var form = document.forms[0];
38-
var batfile = form.elements['batfile'].value;
38+
var srcfile = form.elements['srcfile'].value;
3939
var distname = form.elements['distname'];
40-
distname.value = batfile.split('\\').pop().replace(/\.[^/.]+$/, '');
40+
distname.value = srcfile.split('\\').pop().replace(/\.[^/.]+$/, '');
4141
}
4242

4343
function splitPath(input) {
@@ -55,9 +55,12 @@ function isRequired(input) {
5555
return true;
5656
}
5757

58-
function hasExtension(input, extension) {
59-
if (input.indexOf(extension, this.length - extension.length) == -1){
60-
errorFeedback('.is-' + extension, 'Not a ' + extension + ' file');
58+
function hasExtension(input, extensions, feedback) {
59+
var hasOne = extensions.filter(function(value){
60+
return input.indexOf(value, this.length - value.length) > -1
61+
})
62+
if (!hasOne[0]){
63+
if (feedback) errorFeedback('.is-ext', 'Not a ' + extensions + ' file');
6164
return false;
6265
}
6366
return true;

hta/thebatchman.hta

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4+
<meta http-equiv="x-ua-compatible" content="ie=9">
5+
<script language="javascript">
6+
var appSize = { width: 350, height: 490 };
7+
window.resizeTo(appSize.width, appSize.height);
8+
window.moveTo((screen.width - appSize.width) / 2, (screen.availHeight - appSize.height) / 2);
9+
</script>
410
<title>The Batchman</title>
511
<hta:application id="app" scroll="auto" sysmenu="yes" showInTaskbar="yes" caption="yes" border="thin" icon="../thebatchman_icon.ico" maximizebutton="no" minimizebutton="no" navigable="yes" singleInstance="yes">
6-
<meta http-equiv="x-ua-compatible" content="ie=9">
7-
<link rel="stylesheet" href="css/bootstrap.min.css">
8-
<link rel="stylesheet" href="css/custom.css">
9-
<script language="javascript" src="js/process.js"></script>
12+
<link rel="stylesheet" href="bootstrap.min.css">
13+
<link rel="stylesheet" href="custom.css">
14+
<script language="javascript" src="process.js"></script>
1015
</head>
1116
<body>
1217
<nav class="navbar navbar-default mb10">
1318
<span class="navbar-brand pt10"><img src="../thebatchman_icon.ico"></span>
14-
<p class="navbar-text"><code>batch -> executable</code></p>
19+
<p class="navbar-text"><code>batch/hta -> executable</code></p>
1520
</nav>
1621
<div class="container-fluid pl20 pr20">
1722
<div class="row">
1823
<div class="col-xs-12">
1924
<form>
2025

21-
<div class="form-group is-required is-bat">
22-
<label class="control-label">Batch File&nbsp;<big class="text-danger">*</big></label>
23-
<input type="file" name="batfile" class="form-control input-sm" value="" onchange="changeDistname()">
26+
<div class="form-group is-required is-ext">
27+
<label class="control-label">Batch or HTA File&nbsp;<big class="text-danger">*</big></label>
28+
<input type="file" name="srcfile" class="form-control input-sm" value="" onchange="changeDistname()">
2429
<strong class="form-control-feedback hide">&#10006;</strong>
2530
</div>
2631

hta/wait.hta

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="x-ua-compatible" content="ie=9">
5+
<script language="javascript">
6+
window.resizeTo(350,200);
7+
window.moveTo((screen.width - 350) / 2, (screen.availHeight - 200) / 2);
8+
setTimeout(function() {
9+
window.close();
10+
}, 2000);
11+
</script>
12+
<title>The Batchman</title>
13+
<hta:application id="app" scroll="auto" sysmenu="no" showInTaskbar="no" caption="yes" border="thin" icon="../thebatchman_icon.ico" maximizebutton="no" minimizebutton="no" navigable="no" singleInstance="yes">
14+
15+
<link rel="stylesheet" href="bootstrap.min.css">
16+
<link rel="stylesheet" href="custom.css">
17+
18+
</head>
19+
<body>
20+
<nav class="navbar navbar-default mb20">
21+
<span class="navbar-brand pt10"><img src="../thebatchman_icon.ico"></span>
22+
<p class="navbar-text"><code>batch -> executable</code></p>
23+
</nav>
24+
<div class="container-fluid">
25+
<div class="row">
26+
<div class="col-xs-12">
27+
<h3 class="text-center">Please Wait...</h3>
28+
</div>
29+
</div>
30+
</div>
31+
</body>
32+
</html>

readme.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
> Slapping those *quick and dirty* **batch** scripts into **executable** programs, one at a time...
55
6-
The Batchman converts Windows batch files into compressed executable files, with the following options :
6+
The Batchman converts Windows batch or HTA files into compressed executable files, with the following options :
77

8-
+ Include files located in the folder of your batch file.
8+
+ Include files located in the folder of your file.
99
+ Customize the icon.
10-
+ Run your executable without showing the console.
11-
+ If the console is hidden, add a completion feedback in the form of a dialog box.
10+
+ Run your executable without showing the console. (for batch files)
11+
+ If the console is hidden, add a completion feedback in the form of a dialog box. (for batch files)
1212

1313
#### Screenshot
1414
![The Batchman Screenshot](screenshot.png)
@@ -19,14 +19,14 @@ The Batchman distribution is itself a batch/HTA/JS application packaged into a n
1919

2020
## Usage
2121
Simply run thebatchman.exe and fill in the form.
22-
The application will **output the executable file to the same folder** where your batch file resides.
22+
The application will **output the executable file to the same folder** where your batch/HTA file resides.
2323

2424
### Options
25-
+ **Include all the other files located in the same folder of your batch script :**
26-
You you can package and use any binary or other dependency in a portable way.
27-
+ **Hide the console when running your executable program :**
25+
+ **Include all the other files located in the same folder of your batch/HTA script :**
26+
You can package and use any binary or other dependency in a portable way.
27+
+ **Hide the console when running your executable program (Batch) :**
2828
By default, running Batch scripts on Windows launches the console. Executables made with The Batchman actually run the batch script packaged inside. You have the possibility to hide the console while the executable is running.
29-
+ **Add a completion feedback :**
29+
+ **Add a completion feedback (Batch) :**
3030
If you choose to hide the console during the execution of your program, you might want to have a feedback to know when the script has ended.
3131
To achieve that, The Batchman adds a label named `completion` and a few lines at the end of your batch script starting a small HTA alert box when it reaches it.
3232
So think of adding `goto completion` in your script instead of `goto:eof` if you want this feature to work correctly.
@@ -46,4 +46,4 @@ Tested on Windows 10 x64, but should work on every Windows up to XP SP2 (x86 or
4646
This project is itself licensed under the terms of the GNU GPLv2 license.
4747

4848
## Notes
49-
This application is for "quick and dirty" purposes. Both HTA and Batch are legacy technologies, even if they're still supported on modern Windows platforms, Microsoft encourages you to use Powershell instead of Batch and WPF (or whatever it is now as you're reading this) instead of HTA for GUI.
49+
This application is for "quick and dirty" purposes. Both HTA and Batch are legacy technologies, even if they're still supported on modern Windows platforms.

thebatchman.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ for /f "tokens=1-7 delims=~" %%i in ('mshta.exe "%~dp0\hta\thebatchman.hta"') do
1111
set "icofile=%%o"
1212
)
1313
if "%srcfile%"=="" goto :eof
14+
start "" mshta.exe "%~dp0\hta\wait.hta"
1415
set "distexe=%srcdir%\%name%.exe"
1516
set "tmpfile=%temp%\%srcfile%"
1617
copy /y "%srcdir%\%srcfile%" "%tmpfile%"
@@ -22,7 +23,7 @@ if exist "%distexe%" del /q /f "%distexe%"
2223
if "%completion%" == "true" (
2324
>>"%tmpfile%" echo(
2425
>>"%tmpfile%" echo :completion
25-
>>"%tmpfile%" echo start /wait "" mshta.exe "javascript:alert('%name% complete');close()"
26+
>>"%tmpfile%" echo start "" mshta.exe "javascript:alert('%name% complete');close()"
2627
)
2728

2829
:: Compress files with 7z

0 commit comments

Comments
 (0)