我想使用文件输入来打开保存对话框,而不是打开对话框。这将允许用户给出输出位置。在我的申请中。
我的HTA代码是<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:toolsffmpegbinffmpeg.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>
提前致谢
没有本机Windows脚本主机界面的"另存为"对话框从我所读到的。我发现生成对话框最简单的方法是从。net中借用。PowerShell可以很容易地处理。net对象。下面是一个批处理/PowerShell混合脚本,它将打开另存为对话框,强制使用。mp4扩展名:
<# : 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
考虑到这一点,您可以将脚本写入%temp%,并使用Shell.Exec()执行它,以便在HTA脚本函数中捕获STDOUT。脚本完成后,可以删除临时批处理文件。如下例中的saveDlg()
函数
<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>