1

I want to use a file input to open a save dialog instead of a open dialog. This will allow the user to give output locations. in my application.

My HTA code is

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="HTATest"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>

<script>
function sync()
{
  var InputTextbox = document.getElementById('InputTextbox');
  var OutputTextbox = document.getElementById('OutputTextbox');
  OutputTextbox.value = InputTextbox.value;
}
</script>

</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 bgcolor="buttonface">
<p><font face="verdana" color="red">VOB to MP4 Converter</font></p>
 <p>
    Input : <input type="file" name="InputTextbox" size="30"><P>
    Output: <input type="text" name="OutputTextbox" size="30"
    ><font>Please change file extention to required format</font><br>

    <input id=runbutton  type="button" value="Convert!" name="run_button"  onClick="TestSub">
</p>
</body>

Thank in Advance

  • Please check if [my answer](http://stackoverflow.com/a/28672540/3439404) to [VBScript file or folder selection](http://stackoverflow.com/q/28632270/3439404) could help? – JosefZ Oct 27 '16 at 06:05
  • What does this have to do with batch files? – Squashman Oct 27 '16 at 12:39

1 Answers1

4

There's no native Windows Scripting Host interface for the "Save As" dialog from what I've read. Easiest way I've found to produce the dialog is to borrow from .NET. PowerShell works with .NET objects pretty easily. Here's a Batch / PowerShell hybrid script that will open the Save As dialog, forcing a .mp4 extension:

<# : batch portion
@powershell -noprofile "iex (${%~f0} | out-string)"
@exit /b
: end batch / begin PowerShell #>
add-type -as System.windows.forms
$save = New-Object Windows.Forms.SaveFileDialog
$save.initialDirectory = $pwd.path
$save.filter = "MP4 files (*.mp4)|*.mp4"
$save.ShowHelp = $true
[void]$save.ShowDialog()
$save.filename

With this in mind, you can write the script to %temp% and execute it using Shell.Exec() in order to capture the STDOUT within your HTA script functions. Once the script is completed, the temporary batch file can be deleted. See the saveDlg() function in the following example.

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="HTATest"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<textarea style="display: none" id="save_bat">
<# : batch portion
@powershell -noprofile -window hidden "iex (${%~f0} | out-string)"
@exit
: end batch / begin PowerShell #>
add-type -as System.windows.forms
$save = New-Object Windows.Forms.SaveFileDialog
$save.initialDirectory = $pwd.path
$save.filter = "MP4 files (*.mp4)|*.mp4"
$save.ShowHelp = $true
[void]$save.ShowDialog()
$save.filename
</textarea>

<script language="JavaScript">
function saveDlg() {
    var fso = new ActiveXObject("Scripting.FileSystemObject"),
        shell = new ActiveXObject("WScript.Shell"),
        temp = shell.Environment("Process")("temp"),
        batfile = fso.createTextFile(temp + "\\save.bat", true),
        saveLoc;

    batfile.write(document.getElementById("save_bat").value);
    batfile.close();

    var proc = shell.Exec(temp + "\\save.bat");
    while (!proc.Status && !saveLoc) {
        saveLoc = proc.StdOut.ReadLine();
        proc.Terminate();
    }
    fso.DeleteFile(temp + "\\save.bat", 1);
    return saveLoc;
}

function goBabyGo() {
    var shell = new ActiveXObject("Wscript.Shell");
    shell.run("h:\\tools\\ffmpeg\\bin\\ffmpeg.exe -i "
        + document.getElementById("InputTextbox").value
        + ' '
        + document.getElementById('OutputTextbox').value
    );
}
</script>

<body bgcolor="buttonface">
<p><font face="verdana" color="red">VOB to MP4 Converter</font></p>
 <p>
    Input : <input type="file" id="InputTextbox" size="30" />
</p>
<p>
    Output: <input type="text" id="OutputTextbox" size="30" readonly />
    <button onclick="document.getElementById('OutputTextbox').value = saveDlg()">Save As...</button>
</p>
<p>
    <input id=runbutton type="button" value="Convert!" name="run_button"  onClick="goBabyGo()" />
</p>
</body>
</html>
Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101