obfuscating batch+HTA hybrid script - batch-file

Following is the hybrid batch script:
<!-- :: Batch section
#echo off
setlocal
echo Select an option:
for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a"
echo End of HTA window, reply: "%{HTAreply}%"
pause
goto :EOF
-->
<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="no" >
<TITLE>HTA Buttons</TITLE>
<SCRIPT language="JavaScript">
window.resizeTo(374,100);
function closeHTA(reply){
var fso = new ActiveXObject("Scripting.FileSystemObject");
fso.GetStandardStream(1).WriteLine(reply);
window.close();
}
</SCRIPT>
</HEAD>
<BODY>
<button onclick="closeHTA(1);">First option</button>
<button onclick="closeHTA(2);">Second option</button>
<button onclick="closeHTA(3);">Third option</button>
</BODY>
</HTML>
Output:
I obfuscated it as stated here : [Post#21]
https://www.dostips.com/forum/viewtopic.php?t=7990&start=15
but then the HTA app output isn't as before. It is as follows:
The entire batch content is displayed in the HTML window.
I want to know why this happens and secondly is there any way to obfuscate this hybrid batch script
Same happens when I try to convert the batch file to exe.
Edit
Problem solved. There was an error in html code. apologies. I would have edited to show the problem but I guess it was too trivial to do that.

Related

CMD - Batch - HTA

I am really new to coding (I started around 3 weeks back) I have found Robocopy and have written a really simple batch file that basically copies a folder from a master directory and then pastes in into a sub folder in 2 destinations that I have specify when I launch the batch file.
This looks messy and I have been trying HTAs and trying to get it so that I can type the variable into the HTA and then that do everything else for me. I was thinking this would just look nicer than a CMD window.
I have got the HTA in a simple version that I will style later but I just cannot figure out how to pass the variable into the batch file or if there is a better way to do this. I have read through so many posts on this, but they all seem far more complex than what I need and ultimately I am failing.
My batch file is currently
CODE:
set /p dest=Please enter destination:
robocopy "D:\MasterFolder\- Details" "E:\Sets\%dest%" /E /V /NP /R:10 /W:30
robocopy "D:\MasterFolder\- Details" "F:\%dest%" /E /V /NP /R:10 /W:30
This does work well but just isn't very nice to look at, I was hoping that with a HTA I could get away from the first line and have that input in a GUI. So far I have managed to come up with the following I just need some help to get this to take the variable from the HTA and place this into the batch file. Or some guidance if there is a better way that this can be achieved
<head>
<title>Folder Creator</title>
<HTA:APPLICATION
APPLICATIONNAME="HTA Folder Creator"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
</head>
<script type="text/javascript">
window.resizeTo(400,200);
</script>
<body>
<label for="dest">Destination:</label>
<input type="text" id="dest">
<br><br>
<button onclick="closeHTA(true);">Create</button>
</body>
Here is an example to take a variable from HTA to batch script :
Reply_from_HTA.bat
<!-- :: Batch section
#echo off
Title Pass variable from HTA to batch
for /F "delims=" %%a in ('mshta.exe "%~F0"') do set "HTAreply=%%a"
echo End of HTA window, reply from HTA GUI : "%HTAreply%"
Set "dest=%HTAreply%"
echo robocopy "D:\MasterFolder\- Details" "E:\Sets\%dest%" /E /V /NP /R:10 /W:30
echo robocopy "D:\MasterFolder\- Details" "F:\%dest%" /E /V /NP /R:10 /W:30
pause>nul
goto :EOF
-->
<HTML>
<HEAD>
<HTA:APPLICATION SCROLL="no" SYSMENU="no" >
<TITLE>HTA GUI Form</TITLE>
<SCRIPT language="Vbscript">
Sub window_onload()
CenterWindow 200,150
Focus
End Sub
Sub CenterWindow(x,y)
window.resizeTo x, y
iLeft = window.screen.availWidth/2 - x/2
itop = window.screen.availHeight/2 - y/2
window.moveTo ileft, itop
End Sub
Function closeHTA(reply)
Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetStandardStream(1).WriteLine(reply)
window.close()
End Function
Sub Focus()
txt.Focus
End Sub
</SCRIPT>
</HEAD>
<BODY>
<center>
<label for="dest">Please enter destination</label>
<br>
<input type="text" id="txt">
<br><Input type="Submit" onclick="closeHTA(txt.value)" value="Submit">
</center>
</BODY>
</HTML>

How can you print an inequality sign without quotes?

Is there a way I can make the output display the proper text. When I have tried this the inequality sign do not show up unless you put " around it and it displays the quotes too. Is there a way it can not print the parenthesis and still display the > or < sign?
The code I am trying to use looks like the following...
set /p projectname=Enter Project Name:
cd %USERPROFILE%\Desktop\Output
echo <html> >>%projectname%.html
echo <head> >>%projectname%.html
echo <link rel="stylesheet" href="%projectname%.css">">>%projectname%.html
echo </head> >>%projectname%.html
I want the output to look like the following...
<html>
<head>
<link rel="stylesheet" href="(project name).css">
Escape each redirector that is to be echoed as text with ^ Thus: ^< or ^>
for instance
echo ^<head^> >>%projectname%.html
or better (no trailing space)
>>%projectname%.html echo ^<head^>
or better still
(
echo whatever
echo whatever else
echo whatever else again
)>filename
where > becomes >> to append (> means 'create file anew')
(only need to redirect to file once)

*.HTA with batch file user entered variables

I want to create a HTA that uses a batch file, when a user fills in the textboxes it will pass the data to the batch file.
My batch file is :
//batch
#ECHO OFF
CD "h:\tools\ffmpeg\bin"
set /p input="Enter input file: "
set /p output="Enter output file: "
ffmpeg.exe -i %input% %output%
I want to pass the input and output from the HTA to the batch file
set /p input="enter input"
set /p output="enter output"
%input% %output%
Pretty sure you don't need to use a batch file at all for this.
Something like this should work:
Set Shell = CreateObject("WScript.Shell")
Shell.run "h:\tools\ffmpeg\bin\ffmpeg.exe -i " & Input & " " & Output
Note - I am just guessing at the variable names (Input and Output) you are using in the HTA, so you will have to rename those to whatever the variables are that contain the inputs you originally wanted to pass through to the batch file. Also only guessing that it will be in VBScript...
EDIT:
To answer the comment more completely, something like this:
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTATest"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
Sub TestSub
Set Shell = CreateObject("WScript.Shell")
Shell.run "h:\tools\ffmpeg\bin\ffmpeg.exe -i "& InputTextbox.Value & " " & OutputTextbox.Value
End Sub
</SCRIPT>
<body>
Input : <input type="text" name="InputTextbox" size="30"><P>
Output: <input type="text" name="OutputTextbox" size="30"><P>
<input id=runbutton type="button" value="Run Script" name="run_button" onClick="TestSub">
</body>
Note for people actually trying to pass arguments to a batch file from HTA:
Assuming you've taken input from the user already you can pass it to the batch file (just like the parameters are passed to the EXE above), but you wouldn't need the set /p lines. Instead you would reference input and output as %1 and %2 in the batch file.

Opening URLs with user input in CMD Batch File

I'm a Static Web Dev. & I Don't know much about CMD & Batch Files.
But I need to make a batch file that does this:It first prompts user to enter a specific word & there are some links that have URL & a some kind of name. then if user's input matches one of the link's names, The URL opens in a browser (the default one). I think it is like this with HTML+JS:
<!doctype html>
<html>
<head>
<script>
function input(){
var stackoverflow = "http://stackoverflow.com";
var val = document.getElementById("input").value;
if (val = stackoverflow){
window.open(stackoverflow);
}
}
</script>
</head>
<body>
<input type="text" id="input" onKeyUp="input()"/>
</body>
</html>
but there should be more options & I think it should be done with START command.
Any help is appreciated.THX
What you are looking for is a simple menu,
:: turn off "verbose" command writeback.
#echo off
:: write a simple list of options to console,
:main
echo Options;
echo 1 : StackOverflow
echo 2 : Google
echo 3 : Youtube
echo 4 : This question
:: Prompt for input,
set /p "strMenu=Enter desired URL number:"
:: Compare input through if commands,
:: `if not defined strMenu goto :menu` can be used here if prefered.
if "%strMenu%" equ "1" start "" "https://www.stackoverflow.com"
if "%strMenu%" equ "2" start "" "https://www.Google.com"
if "%strMenu%" equ "3" start "" "https://www.youtube.com"
if "%strMenu%" equ "4" start "" "http://stackoverflow.com/questions/35945614/opening-urls-with-user-input-in-cmd-batch-file"
exit
Note the start command will use the default assigned browser, but this can be set with something like;
start "" "chrome" "URL"
Numbers are used for laziness in having to type more than 1 character before hitting enter.

Javascript file loads twice

In my view, when I call inline execution <?php echo $this->Html->script('forms/contact');?> it executes okay, but when I want the script to be loaded within the head tags it generates the code twice.
In my view:
<?php $this->Html->script('forms/contact', array('inline' => false));?>
Output:
<script type="text/javascript" src="/animalmedica/js/forms/contact.js"></script>
<script type="text/javascript" src="/animalmedica/js/forms/contact.js"></script>
Any ideas why?
I can't answer your question as to why, but I had exactly the same issue. After some trial and error I came up with this solution:
In my default layout I was using both the fetch script method and scripts for layout. I only needed one
echo $this->Html->charset();
echo $this->Html->meta('icon');
echo $this->Html->css('cake.generic');
echo $this->Html->css('grid_layout');
echo $this->Html->css('style');
echo $this->Html->css('jquery-ui-1.10.3.custom');
echo $this->Html->script('countdown');
echo $this->Html->script('page');
echo $this->fetch('meta');
echo $this->fetch('css');
echo $this->fetch('script');
echo $this->Js->writeBuffer(array('cache'=>FALSE));
//echo $scripts_for_layout;
scripts for layout is now deprecated:
http://book.cakephp.org/2.0/en/views.html#using-blocks-for-script-and-css-files

Resources