我想使用文件输入来打开保存对话框而不是打开对话框。这将允许用户给出输出位置。在我的申请中。
我的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:\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>
先谢谢
答案 0 :(得分:3)
“另存为”对话框from what I've read没有本机Windows Scripting Host界面。我发现生成对话框的最简单方法是从.NET借用。 PowerShell非常容易与.NET对象一起使用。这是一个Batch / 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>