HTML应用程序(HTA)是Microsoft Windows程序,其源代码由HTML,动态HTML和Internet Explorer支持的一种或多种脚本语言(如VBScript或JScript)组成。如果您的问题是关于HTA中的脚本,请始终提及或添加使用的脚本语言的标记。
VBScript 使用生成的 URL 启动 Internet Explorer
目前我正在学习HTA编程。 我有一个要求如下。 表单中有两个输入框(均为必填)。 当我输入值并单击搜索按钮时,会出现一个网址...
我在 Windows 7/10 中使用以下脚本打开文件对话框并允许用户选择文件。即使添加了多个属性,它也不允许我选择多个文件。雅高...
我们的业务使用 Macro Express Pro 创建宏来协助日常任务。我不是多次提示用户输入数据,而是创建一个 HTA 并使用 ...
HTML 应用程序 (hta) 中的 vbscript 中的 ACE OLEDB 提供程序读取 Excel 时表示未安装提供程序,vbs 正在工作,但 hta 不工作
我想读取一个excel表格并用vbscript显示内容。我还希望用户能够选择源目录,因此添加了 hta Furteron。 ACE OLEDB 提供商必须...
简单的 javascript 函数可将下一个/上一个 H1 滚动到屏幕顶部 - 在使用 MSHTA.exe 运行的 HTA 应用程序中
我是一名业余程序员,并制作了一个 HTA 文件,其中包含一些 JavaScript 和一个可编辑的内容 。使用最少的 JavaScript,我可以设置键盘快捷键来格式化、保存和退出。 ... 我是一名业余程序员,并且制作了一个 HTA 文件,其中包含一些 JavaScript 和一个可编辑的内容 <DIV>。使用最少的 JavaScript,我可以设置键盘快捷键来格式化、保存和退出。 我正在完全更新的 Windows 10 系统中使用 mshta32.exe 运行该文件。我的空 HTA 只有 12k,为此我可以进行自动换行、格式化、链接图像、打印(包括 PDF)和实时拼写检查!它不是文字处理程序,但对于无干扰的写作,我很喜欢这种体验。 我的下一个目标是使用这些文件进行演示;我需要的最少功能是“下一张幻灯片”和“上一张幻灯片”快捷方式。使用 <H1> 标签作为幻灯片标题似乎是合理的,因此我的快捷方式只需要滚动,以便下一个或上一个 <H1> 位于屏幕顶部(是的,HTA 确实以大写形式保存标签)。 在互联网/ChatGPT 上有使用 document.querySelector 的解决方案,但这似乎在 HTA/MSHTA 中不受支持(我尝试过使用 content=ie=edge 和 http-equiv=X-UA-Compatible 的元标记)。不热衷于 JQuery,因为这是一个极简主义项目,需要离线工作,所以我尝试用 jQuery 翻译一个建议: 制作一个滚动到下一个标题的跳过按钮 $('html, body').scrollTop($(this).nextInDOM($('h1, h2, h3, h4, h5, h6')).position().top); event.preventDefault(); 至 JavaScript: document.querySelector('html, body').scrollTop(document.querySelector(this).nextInDOM(document.querySelector('h1, h2, h3, h4, h5, h6')).position().top); event.preventDefault(); 这不起作用!欢迎任何指导。 亲切的问候加文霍尔特 整个HTA <!DOCTYPE html> <HTML> <HEAD unselectable="on"> <TITLE unselectable="on"> ContentEditor - O:\MyProfile\editor\templates\default.hta</TITLE><?XML:NAMESPACE PREFIX = "HTA" /> <HTA:Application id=document.currentScript VERSION="2" SYSMENU="yes" Singleinstance="no" ShowInTaskBar="yes" scroll="yes" NAVIGABLE="yes" MinimizeButton="yes" MaximizeButton="yes" Icon="O:\MyProfile\cmd\IcoFX\ContentEditor.ico" ContextMenu="No" Border="No" APPLICATIONNAME="MSI-BUILD"></HTA:Application> <BASE target=_blank unselectable="on"> <META name=viewport content="width=device-width, initial-scale=1" unselectable="on"> <META content=ie=edge unselectable="on"> <META http-equiv=X-UA-Compatible unselectable="on"> <STYLE unselectable="on"> @media Unknown { .sidenav { PADDING-TOP: 15px } } HTML { COLOR: #657b83; MARGIN: 1em; BACKGROUND-COLOR: #fdf6e3 } BODY { FONT-SIZE: 24px; FONT-FAMILY: Helvetica, arial, sans-serif; LETTER-SPACING: 0px; BACKGROUND-COLOR: #fdf6e3 } .sidenav { FONT-SIZE: 22px; OVERFLOW: hidden; HEIGHT: 100%; WIDTH: 0px; OVERFLOW-X: hidden; POSITION: fixed; PADDING-TOP: 4px; LEFT: 0px; Z-INDEX: 1; TOP: 0px; BACKGROUND-COLOR: #111; transition: 0.5s } .sidenav A { TEXT-DECORATION: none; COLOR: #818181; PADDING-BOTTOM: 8px; PADDING-TOP: 8px; PADDING-LEFT: 32px; DISPLAY: block; PADDING-RIGHT: 8px; transition: 0.3s } .sidenav P { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } TD { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } TH { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } B { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } U { COLOR: #818181; PADDING-BOTTOM: 4px; PADDING-TOP: 8px; PADDING-LEFT: 4px; PADDING-RIGHT: 4px } .sidenav A:hover { COLOR: #f1f1f1 } .sidenav TABLE { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TR { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TD { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } TH { BORDER-LEFT-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; LINE-HEIGHT: 1; BORDER-TOP-WIDTH: 0px } #editor { PADDING-BOTTOM: 16px; PADDING-TOP: 16px; PADDING-LEFT: 16px; PADDING-RIGHT: 16px; transition: margin-left .5s } H1 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H2 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H3 { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } P { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } A { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } CODE { FONT-SIZE: 24px; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } H1 { FONT-SIZE: 26px; FONT-VARIANT: small-caps } TABLE { WIDTH: 95%; BORDER-COLLAPSE: collapse } TABLE { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TD { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TH { BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none } TR { VERTICAL-ALIGN: top; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } TD { VERTICAL-ALIGN: top; TEXT-ALIGN: left; LINE-HEIGHT: 1.2 } TD { } TH { } TABLE { PAGE-BREAK-INSIDE: auto } TR { PAGE-BREAK-INSIDE: avoid; PAGE-BREAK-AFTER: auto } THEAD { DISPLAY: table-header-group } TFOOT { DISPLAY: table-footer-group } </STYLE> <SCRIPT language=JScript type=text/jscript unselectable="on"> <!-- function preventDefault(e){ if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; } } function toggleNav() { if (document.getElementById("mySidenav").style.width=="260px") { closeNav(); } else { openNav(); } } function openNav() { document.getElementById("mySidenav").style.width = "260px"; document.getElementById("editor").style.marginLeft = "260px"; document.getElementById("mySidenav").style.overflow = "scroll"; } function closeNav() { document.getElementById("mySidenav").style.width = "0"; document.getElementById("editor").style.marginLeft= "0"; document.getElementById("mySidenav").style.overflow = "hidden"; } function writeFile(){ // Deal with funny \ at work! var filename = window.location.pathname var fso, fileHandle; fso = new ActiveXObject("Scripting.FileSystemObject"); fileHandle = fso.CreateTextFile(filename.replace(/\//,""), true); fileHandle.write("<!DOCTYPE html>"); fileHandle.write("<HTML>"); fileHandle.write(document.documentElement.innerHTML); fileHandle.write("</HTML>"); fileHandle.close(); } function getSelected() { if (window.getSelection) { return window.getSelection(); } else if (document.getSelection) { return document.getSelection(); } else { var selection = document.selection && document.selection.createRange(); if (selection.text) { return selection.text; } return false; } } function insertText(text) { if (document.selection){ var range = document.selection.createRange(); range.pasteHTML(text); } } function followlink(){ alert('followlink called'); } function popupmenu(event) { alert('popupmenu called'); // Need to know the event.target - but don't want jquery! // use window.screenLeft window.screenTop } function Shortcuts(e){ if (!e) var e = window.event; var key = e.keyCode if (e.ctrlKey) { key = "ctrl"+key; } if (e.altKey) { key = "alt"+key; } if (e.shiftKey) { key = "shift"+key; } // alert(key) // ESC if ( key == 27) { writeFile(); window.close(); } // TAB alone if ( key == 9) { preventDefault(e); document.execCommand("indent", true, null); return false; } // Shift+TAB if (key == "shift9") { preventDefault(e); document.execCommand("outdent", true, null); return false; } // Ctrl+> if ( key == "ctrl190") { document.execCommand("indent", true); } // Ctrl+< if ( key == "ctrl188") { document.execCommand("outdent", true); } // Ctrl+Up TODO: Fails with this key if ( key == "ctrl38") { document.execCommand("superscript", true); } // Ctrl+Down TODO: Fails with this key if ( key == "ctrl40") { document.execCommand("subscript", true); } // Ctrl++ - Built in zoom+ // Ctrl+- - Built in zoom- // Ctrl+/ Try to wrap any selection if ( key == "ctrl191") { var sText = getSelected(); var code = "<code>" + sText + "</code>" insertText(code); } // Ctrl+\ Clear formatting if ( key == "ctrl220") { document.execCommand("removeFormat", true); } // Ctrl+A - Built in select all // Ctrl+B - Built in bold // Ctrl+C - Built in copy // Ctrl+D if ( key == "ctrl68") { document.execCommand("strikethrough", true); } // Ctrl+E - Editor if ( key == "ctrl69") { WshShell = new ActiveXObject("WScript.Shell"); WshShell.Run("O:/MyProfile/editor/micro.bat " + window.location.pathname,1,true) } // Ctrl+F - Built in Find // Ctrl+G - Google if ( key == "ctrl71") { WshShell = new ActiveXObject("WScript.Shell"); WshShell.run("http://www.google.com"); } // Ctrl+H - Hyperlink if ( key == "ctrl72") { var sText = getSelected(); var linkURL = prompt('Enter a URL:', 'http://'); // This is to match the automated format when URL is pasted/typed var link = '<A href="' + linkURL + '" target="_blank">' + sText + '</A>'; insertText(link); } // Ctrl+I - Built in italic // Ctrl+J - Jump to next H1 - for slide presentations if ( key == "ctrl74") { } // Ctrl+K - Built in hyperlink // Ctrl+L - Ordered list if ( key == "ctrl76") { document.execCommand("insertUnorderedList", true); } // Ctrl+M if ( key == "ctrl77") { // Undo default action of CRLF return false; } // Ctrl+N - Numbered List if ( key == "ctrl78") { document.execCommand("insertOrderedList", true); } // Ctrl+O - Empty // Ctrl+P - Built in Print // Ctrl+Q - Empty // Ctrl+R - Revert if ( key == "ctrl82") { window.location.reload(false); } // Ctrl+S - Save if ( key == "ctrl83") { writeFile(); } // Ctrl+T - Insert Table - TODO: need some css or in line styles if ( key == "ctrl84") { document.execCommand("indent", true, null); var table = "<table>" table = table +"<tr>" table = table +" <th>Company</th>" table = table +" <th>Contact</th>" table = table +" <th>Country</th>" table = table +"</tr>" table = table +"<tr>" table = table +" <td>Alfreds</td>" table = table +" <td>Maria</td>" table = table +" <td>Germany</td>" table = table +"</tr>" table = table +"<tr>" table = table +" <td>Centro</td>" table = table +" <td>Francisco</td>" table = table +" <td>Mexico</td>" table = table +"</tr>" table = table +"</table>" insertText(table); } // Ctrl+U - Built in Underline // Ctrl+V - Built in Paste // Ctrl+W - Write and Close if ( key == "ctrl87") { writeFile(); window.close(); } // Ctrl+X - Built in Cut // Ctrl+Y - Built in Redo // Ctrl+Z - Built in Undo // F1 if ( key == 112) { toggleNav(); } // Ctrl+0 if ( key == "ctrl48") { document.execCommand("formatBlock", false, "<P>"); } // Ctrl+1 if ( key == "ctrl49") { document.execCommand("formatBlock", false, "<H1>"); } // Ctrl+2 if ( key == "ctrl50") { document.execCommand("formatBlock", false, "<H2>"); } // Ctrl+3 if ( key == "ctrl51") { document.execCommand("formatBlock", false, "<H3>"); } } // Try to stop focus outside my div for (i=0; i<document.all.length; i++){ //ensure that all document elements except the content editable DIV are unselectable document.all(i).unselectable = "on"; } // Change title var filename = window.location.pathname document.title = " ContentEditor - " + filename.replace(/\//,"") // Focus on the editable section window.location.hash = '#editor'; // Settings document.execCommand("LiveResize", null, true); //--> </SCRIPT> </HEAD> <BODY tabIndex=-1> <DIV tabIndex=-1 id=mySidenav class=sidenav style="OVERFLOW: scroll; WIDTH: 260px" unselectable="on"><U><B>Help</B></U> <TABLE> <TBODY> <TR> <TD>ESC </TD> <TD>Save + exit</TD></TR> <TR> <TD>TAB </TD> <TD>Indent</TD></TR> <TR> <TD>Shift+TAB </TD> <TD>Outdent</TD></TR> <TR> <TD>Ctrl+A </TD> <TD>Select All</TD></TR> <TR> <TD>Ctrl+B </TD> <TD>Bold</TD></TR> <TR> <TD>Ctrl+C </TD> <TD>Copy</TD></TR> <TR> <TD>Ctrl+D </TD> <TD>Strikeout</TD></TR> <TR> <TD>Ctrl+E </TD> <TD>Edit page</TD></TR> <TR> <TD>Ctrl+F </TD> <TD>Find</TD></TR> <TR> <TD>Ctrl+I </TD> <TD>Italic</TD></TR> <TR> <TD>Ctrl+K </TD> <TD>Hyperlink</TD></TR> <TR> <TD>Ctrl+L </TD> <TD>Bullet list</TD></TR> <TR> <TD>Ctrl+N </TD> <TD>Num list</TD></TR> <TR> <TD>Ctrl+P </TD> <TD>Print</TD></TR> <TR> <TD>Ctrl+R </TD> <TD>Revert</TD></TR> <TR> <TD>Ctrl+S </TD> <TD>Save</TD></TR> <TR> <TD>Ctrl+T </TD> <TD>Insert table</TD></TR> <TR> <TD>Ctrl+U </TD> <TD>Underline</TD></TR> <TR> <TD>Ctrl+V </TD> <TD>Paste</TD></TR> <TR> <TD>Ctrl+W </TD> <TD>Save + exit</TD></TR> <TR> <TD>Ctrl+X </TD> <TD>Cut</TD></TR> <TR> <TD>Ctrl+Y </TD> <TD>Redo</TD></TR> <TR> <TD>Ctrl+Z </TD> <TD>Undo</TD></TR> <TR> <TD>Ctrl+/ </TD> <TD>Code</TD></TR> <TR> <TD>Ctrl+< </TD> <TD>Superscript</TD></TR> <TR> <TD>Ctrl+> </TD> <TD>Subscript</TD></TR> <TR> <TD>Ctrl+\\ </TD> <TD>Unformat</TD></TR> <TR> <TD>Ctrl+Del </TD> <TD>Del EOW</TD></TR> <TR> <TD>Ctrl+Bksp </TD> <TD>Del BOW</TD></TR> <TR> <TD>Ctrl+n </TD> <TD>Heading 1-3</TD></TR> <TR> <TD>F1 </TD> <TD>Toggle Help</TD></TR></TBODY></TABLE> <P></P></DIV> <DIV spellcheck=true tabIndex=-1 onkeyup=Shortcuts() id=editor contentEditable=true onkeydown="return (event.keyCode!=9);" style="MARGIN-LEFT: 260px" oncontextmenu=popupmenu()></DIV> <SCRIPT type=text/javascript> <!-- //--> </SCRIPT> </BODY></HTML> 嗨, 非常感谢迄今为止的所有建议,总而言之: 我的 writeFile() 功能总是会添加 <?XML:NAMESPACE PREFIX = "HTA" />,这使我处于 IE7 模式。 function writeFile(){ // Deal with funny \ at work! var filename = window.location.pathname var fso, fileHandle; fso = new ActiveXObject("Scripting.FileSystemObject"); fileHandle = fso.CreateTextFile(filename.replace(/\//,""), true); fileHandle.write("<!DOCTYPE html>"); fileHandle.write("<HTML>"); fileHandle.write(document.documentElement.innerHTML); fileHandle.write("</HTML>"); fileHandle.close(); } 我需要 <hta:application> 部分来控制窗口和图标。 <hta:application id=document.currentScript applicationname="MSI-BUILD" border="No" contextmenu="No" icon="O:\MyProfile\cmd\ContentEditor.ico" maximizebutton="yes" minimizebutton="yes" navigable="yes" scroll="yes" showintaskbar="yes" singleinstance="no" sysmenu="yes" version="2" > 使用函数查看documentMode和ScriptEngine,我得到带有JScript 11.0.16384的IE7。 ver = 'IE' + document.documentMode + ' , '; ver += ScriptEngine() + ' '; ver += ScriptEngineMajorVersion() + '.'; ver += ScriptEngineMinorVersion() + '.'; ver += ScriptEngineBuildVersion(); alert(ver); 所以,我认为我被 IE7 时代的脚本困住了。 亲切的问候加文霍尔特 您关于如何询问ChatGPT的建议非常有帮助,这个功能正是我所需要的: function scrollToNextH1() { var h1Elements = document.getElementsByTagName('h1'); var currentH1Index = -1; for (var i = 0; i < h1Elements.length; i++) { if (h1Elements[i].getBoundingClientRect().top > 0) { currentH1Index = i; break; } } if (currentH1Index !== -1 && currentH1Index < h1Elements.length - 1) { var nextH1 = h1Elements[currentH1Index + 1]; window.scrollTo(0, nextH1.offsetTop); } } 在这短短的时间内,我学到的东西比用搜索引擎搜索的日子还要多。乐于助人的人和优秀的法学硕士的结合是非常有效的。 非常感谢
更新:我将页面上显示的图像更改为编码版本,而不是引用外部图像。我能够将图像放入 Base64 转换器,然后复制并粘贴...
我遇到了一个问题,试图摆脱cmd弹出窗口并使命令中的所有数据出现在span标签中。我知道足以让命令正常工作,但不知道如何实现
我希望用户通过创建的输入标签提供文件夹或目录的路径,如下所示: var newinput = document.createElement('input'); newinput.type = "文件"; 新输入。
我希望用户通过创建的输入标签提供文件夹或目录的路径,如下所示: var newinput = document.createElement('input'); newinput.type = "文件"; 新输入。
也许这里有人可以帮我修改这个脚本吗?我希望文件名位于 gif 下方,并且文本大小稍小一些,以便更多的 gif 可以出现在一行中。 <p>也许这里有人可以帮我修改这个脚本吗?我希望文件名位于 gif 下方,并且文本大小稍小一些,以便更多的 gif 可以出现在一行中。</p> <pre><code><script type="text/vbs"> set fso=CreateObject("Scripting.FileSystemObject") set fldr=fso.GetFolder(".") for each file in fldr.files if lcase(right(file.name,4))=".gif" then document.write "<img src=""" & file.name & """>" document.write file.name & "&#160;&#160;&#160;&#160;&#160;&#160;" end if next </script> </code></pre> </question> <answer tick="false" vote="0"> <p>如评论中所述,您可以使用一些应用于 Div 的 CSS 并创建一个类来设置图像大小。大小可以指定为任何所需的单位。这里使用 Ems 是因为在设置不同缩放值的显示器上尺寸保持相当恒定。这是 HTA 代码:</p> <p><strong>GIFshow.hta</strong></p> <pre><code><!DOCTYPE html> <html> <head> <meta http-equiv="x-ua-compatible" content="IE=10"> <script language="VBScript"> Set oFSO = CreateObject("Scripting.FileSystemObject") Set oFolder = oFSO.GetFolder(".") For Each oFile In oFolder.Files If LCase(oFSO.GetExtensionName(oFile.Name)) = "gif" Then document.write "<div class=""image-container"">" document.write "<img class=""image"" src=""" & oFile.Name & """ alt=""" & oFile.Name & """>" document.write "<br>" & oFile.Name document.write "</div>" End If Next </script> <style> .image-container { display: inline-block; text-align: center; } .image { width: 10em; height: 10em; } </style> </head> <body> </body> </html> </code></pre> </answer> </body></html>
我需要通过命令行应用程序快速编写一个简单的 GUI。需要两个步骤: 指定输入文件路径, 指定输出文件路径(不存在) 我发现了以前的帖子,h...
BAT/HTA 混合 - 如何转义 HTML 部分中的百分号?
我正在处理批处理/HTA 混合文件,并希望向应用程序添加一些背景音乐。当我尝试将 url(包含百分号)添加到 标签时,它不会播放任何内容...
HTA VBScript:在运行时从字符串或包含字符串的变量动态创建函数,如 Javascript 中使用 new Function() 构造函数
我正在尝试学习更多的 hta 和 VBScript,我想知道 VBS 是否允许像 Javascript 中那样创建动态函数: var f = new Function('函数名', 函数体); 或者 赢...
如何将 HTA 窗口居中,使其位于屏幕中央,无论 HTA 大小的屏幕分辨率如何我有这个: Sub DoResize '不要使用 </desc> <question vote="8"> <p>如何将 HTA 窗口居中,使其位于屏幕中央,无论 HTA 大小的屏幕分辨率如何我有这个:</p> <pre><code></head> <script> Sub DoResize 'Do not use Window_Onload window.resizeTo 800,600 strComputer = "." Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor") For Each objItem in colItems intHorizontal = objItem.ScreenWidth intVertical = objItem.ScreenHeight Next intLeft = (intHorizontal - 800) / 2 intTop = (intVertical - 600) / 2 window.moveTo intLeft, intTop End Sub DoResize() 'Run the subroutine to position the containing window (your HTA dialog) before the body is rendered. </script> <body> </code></pre> <p>但是如果我更改屏幕分辨率,它就不起作用,并且会调整 HTA 窗口的大小。</p> <p>问题:无论屏幕分辨率的 HTA 大小如何,如何将 HTA 移动到屏幕中央。</p> </question> <answer tick="true" vote="6"> <p>为此使用 WMI 有点过分了。您可以使用 <pre><code>screen</code></pre> 对象代替:</p> <pre><code>window.resizeTo (800, 600); window.moveTo((screen.width - 800) / 2, (screen.height - 600) / 2); </code></pre> <p>如果您想在开始时调整窗口大小,请将上面的行放在 <pre><code>script</code></pre> 部分中的 (JS) <pre><code>head</code></pre> 标记中,甚至在 <pre><code><hta: application></code></pre> 标记之前,或者在事件处理程序中或任何位置使用代码需要它。</p> <p>如果您想将任务栏的高度排除在居中区域之外,可以使用 <pre><code>screen.availHeight</code></pre> 代替 <pre><code>screen.height</code></pre>。</p> </answer> <answer tick="false" vote="2"> <pre><code>var winWidth = 800, winHeight = 600; window.resizeTo(winWidth, winHeight); window.moveTo((screen.width - winWidth) / 2, (screen.height - winHeight) / 2); </code></pre> </answer> <answer tick="false" vote="0"> <p>HTA窗口</p> <blockquote> <p>`</p> </blockquote> <p></p><div data-babel="false" data-lang="js" data-hide="false" data-console="true"> <div> <pre><code><!DOCTYPE html> <html> <head> <title>File Operations</title> <hta:application id="FileOperationsHTA" applicationname="FileOperationsHTA" singleinstance="yes" maximizebutton="no" minimizebutton="no" windowstate="normal" scroll="no" navigable="yes" showintaskbar="no" contextmenu="no" selection="no" /> </head> <body onload="showFields()"> <h1>File Operations</h1> <label for="operationCombo">Select operation:</label> <select id="operationCombo" onchange="showFields()"> <option value="">Select an operation</option> <option value="move">Move</option> <option value="copy">Copy</option> <option value="delete">Delete</option> <option value="newfolder">New Folder</option> <option value="rename">Rename</option> </select> <div id="sourceField" style="display: none;"> <label for="sourcePath">Source path:</label> <input type="text" id="sourcePath" /> </div> <div id="destinationField" style="display: none;"> <label for="destinationPath">Destination path:</label> <input type="text" id="destinationPath" /> </div> <div id="deleteField" style="display: none;"> <label for="deletePath">File/Folder to delete:</label> <input type="text" id="deletePath" /> </div> <div id="newFolderField" style="display: none;"> <label for="parentPath">Parent path for new folder:</label> <input type="text" id="parentPath" /> <label for="newFolderName">New folder name:</label> <input type="text" id="newFolderName" /> </div> <div id="renameField" style="display: none;"> <label for="sourcePathRename">Source path:</label> <input type="text" id="sourcePathRename" /> <label for="destinationPathRename">Destination path:</label> <input type="text" id="destinationPathRename" /> <label for="newFileName">New filename:</label> <input type="text" id="newFileName" /> </div> <button id="executeButton" onclick="executeOperation()">Execute</button> <script type="text/javascript"> function showFields() { var operation = document.getElementById('operationCombo').value; var sourceField = document.getElementById('sourceField'); var destinationField = document.getElementById('destinationField'); var deleteField = document.getElementById('deleteField'); var newFolderField = document.getElementById('newFolderField'); var renameField = document.getElementById('renameField'); var executeButton = document.getElementById('executeButton'); sourceField.style.display = 'none'; destinationField.style.display = 'none'; deleteField.style.display = 'none'; newFolderField.style.display = 'none'; renameField.style.display = 'none'; switch (operation) { case 'move': sourceField.style.display = 'block'; destinationField.style.display = 'block'; break; case 'copy': sourceField.style.display = 'block'; destinationField.style.display = 'block'; break; case 'delete': deleteField.style.display = 'block'; break; case 'newfolder': newFolderField.style.display = 'block'; break; case 'rename': renameField.style.display = 'block'; document.getElementById('sourcePathRename').disabled = false; document.getElementById('destinationPathRename').disabled = false; document.getElementById('newFileName').disabled = false; break; } } function executeOperation() { var operation = document.getElementById('operationCombo').value; switch (operation) { case 'move': var sourcePath = document.getElementById('sourcePath').value; var destinationPath = document.getElementById('destinationPath').value; moveFilesWithWildcard(sourcePath, destinationPath); break; case 'copy': var sourcePath = document.getElementById('sourcePath').value; var destinationPath = document.getElementById('destinationPath').value; copyFilesWithWildcard(sourcePath, destinationPath); break; case 'delete': var deletePath = document.getElementById('deletePath').value; deleteFilesWithWildcard(deletePath); break; case 'newfolder': var parentPath = document.getElementById('parentPath').value; var newFolderName = document.getElementById('newFolderName').value; createNewFolder(parentPath, newFolderName); break; case 'rename': var sourcePathRename = document.getElementById('sourcePathRename').value; var destinationPathRename = document.getElementById('destinationPathRename').value; var newFileName = document.getElementById('newFileName').value; renameFile(sourcePathRename, destinationPathRename, newFileName); break; } } function renameFile(sourcePath, destinationPath, newFileName) { var fso = new ActiveXObject("Scripting.FileSystemObject"); if (fso.FileExists(sourcePath)) { try { fso.MoveFile(sourcePath, fso.BuildPath(destinationPath, newFileName)); alert('Rename operation executed.\nSource: ' + sourcePath + '\nDestination: ' + destinationPath); } catch (e) { alert('Error renaming file: ' + e.message); } } else { alert('Source file not found.'); } } function moveFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, "\\.").replace(/\*/g, ".*"), "i"); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { var sourceFile = fso.BuildPath(parentFolder, file.Name); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(sourceFile, destinationFile); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } } catch (e) { alert('Error moving files/folders with wildcard.'); } } else { alert('Parent path not found.'); } } function moveFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(file.Path, destinationFile); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } function copyFiles(sourcePath, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var folder = fso.GetFolder(sourcePath); if (fso.FolderExists(destinationPath)) { try { copyFilesRecursive(folder, destinationPath); alert('Copy operation executed.\nSource Path: ' + sourcePath + '\nDestination Path: ' + destinationPath); } catch (e) { alert('Error copying files/folders.'); } } else { alert('Destination path not found.'); } } function copyFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); fso.CopyFile(file.Path, fso.BuildPath(destinationPath, file.Name), true); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); copyFilesRecursive(subFolder, newDestPath); } } function moveFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, "\\.").replace(/\*/g, ".*"), "i"); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { var sourceFile = fso.BuildPath(parentFolder, file.Name); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(sourceFile, destinationFile); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } } catch (e) { alert('Error moving files/folders with wildcard.'); } } else { alert('Parent path not found.'); } } function moveFilesRecursive(folder, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var files = new Enumerator(folder.Files); var subFolders = new Enumerator(folder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); var destinationFile = fso.BuildPath(destinationPath, file.Name); fso.MoveFile(file.Path, destinationFile); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); var newDestPath = fso.BuildPath(destinationPath, subFolder.Name); fso.CreateFolder(newDestPath); moveFilesRecursive(subFolder, newDestPath); } } function copyFilesWithWildcard(sourcePath, destinationPath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); if (fso.FileExists(sourcePath)) { // Source path is a single file var sourceFolder = fso.GetParentFolderName(sourcePath); var sourceFileName = fso.GetFileName(sourcePath); if (fso.FileExists(destinationPath)) { // Destination path includes a filename, create a new folder in the destination path var destinationParentFolder = fso.GetParentFolderName(destinationPath); var newFolderName = fso.GetBaseName(destinationPath); destinationPath = fso.BuildPath(destinationParentFolder, newFolderName); } else if (!fso.FolderExists(destinationPath)) { // Destination folder does not exist, create it fso.CreateFolder(destinationPath); } // Perform the copy operation fso.CopyFile(sourcePath, fso.BuildPath(destinationPath, sourceFileName)); alert('Copy operation executed.\nSource: ' + sourcePath + '\nDestination: ' + destinationPath); } else if (fso.FolderExists(sourcePath)) { // Source path is a folder var parentFolder = fso.GetParentFolderName(sourcePath); var wildcard = fso.GetFileName(sourcePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, "\\.").replace(/\*/g, ".*"), "i"); // Collect files and folders matching the wildcard var filesToCopy = []; var foldersToCopy = []; for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { filesToCopy.push(file); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { foldersToCopy.push(subFolder); } } // Perform the copy operation if (!fso.FolderExists(destinationPath)) { // Destination folder does not exist, create it fso.CreateFolder(destinationPath); } for (var i = 0; i < filesToCopy.length; i++) { var file = filesToCopy[i]; file.Copy(fso.BuildPath(destinationPath, file.Name)); } for (var i = 0; i < foldersToCopy.length; i++) { var folder = foldersToCopy[i]; copyFolderRecursive(folder, fso.BuildPath(destinationPath, folder.Name)); } alert('Copy operation executed.\nSource: ' + sourcePath + '\nDestination: ' + destinationPath); } catch (e) { alert('Error copying files/folders with wildcard: ' + e.message); } } else { alert('Source parent path not found.'); } } else { alert('Source path not found.'); } } function copyFolderRecursive(sourceFolder, destinationFolder) { var fso = new ActiveXObject("Scripting.FileSystemObject"); fso.CreateFolder(destinationFolder); var files = new Enumerator(sourceFolder.Files); var subFolders = new Enumerator(sourceFolder.SubFolders); for (; !files.atEnd(); files.moveNext()) { var file = files.item(); file.Copy(fso.BuildPath(destinationFolder, file.Name)); } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); copyFolderRecursive(subFolder, fso.BuildPath(destinationFolder, subFolder.Name)); } } function createNewFolder(parentPath, newFolderName) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fullPath = fso.BuildPath(parentPath, newFolderName); try { fso.CreateFolder(fullPath); alert('New folder created successfully.\nPath: ' + fullPath); } catch (e) { alert('Error creating new folder: ' + e.message); } } function deleteFilesWithWildcard(deletePath) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var parentFolder = fso.GetParentFolderName(deletePath); var wildcard = fso.GetFileName(deletePath); var parentFolderObj = fso.GetFolder(parentFolder); if (fso.FolderExists(parentFolder)) { try { var files = new Enumerator(parentFolderObj.Files); var subFolders = new Enumerator(parentFolderObj.SubFolders); var regex = new RegExp(wildcard.replace(/\./g, "\\.").replace(/\*/g, ".*"), "i"); // Collect files and folders matching the wildcard var filesToDelete = []; var foldersToDelete = []; for (; !files.atEnd(); files.moveNext()) { var file = files.item(); if (regex.test(file.Name)) { filesToDelete.push(file); } } for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); if (regex.test(subFolder.Name)) { foldersToDelete.push(subFolder); } } // Delete files for (var i = 0; i < filesToDelete.length; i++) { filesToDelete[i].Delete(); } // Delete folders for (var i = 0; i < foldersToDelete.length; i++) { deleteFolderRecursive(foldersToDelete[i]); } alert('Delete operation executed.\nPath: ' + deletePath); } catch (e) { alert('Error deleting files/folders with wildcard: ' + e.message); } } else { alert('Parent path not found.'); } } function deleteFolderRecursive(folder) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var subFolders = new Enumerator(folder.SubFolders); for (; !subFolders.atEnd(); subFolders.moveNext()) { var subFolder = subFolders.item(); deleteFolderRecursive(subFolder); } fso.DeleteFolder(folder.Path); } </script> </body> </html></code></pre> </div> </div> <p></p> <p>`</p> </answer> <answer tick="false" vote="0"> <p>函数 logMessage(消息) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var logFile = fso.OpenTextFile("file_operations.log", 8, true); // 8 用于追加</p> <pre><code> var now = new Date(); var timestamp = now.toLocaleString(); logFile.WriteLine("[" + timestamp + "] " + message); logFile.Close(); } </code></pre> </answer> </body></html>
我正在尝试在 VBScript 变量中捕获机器的 DNS 服务器地址。这将在 .hta 文件中使用。 到目前为止,我的代码如下。它返回如下所示的错误。我...
我正在写一个HTA,希望用户能够很容易地能够使用浏览器选择一个.txt文件。这个.txt文件将被逐行读取并读入一个数组。所以,我在使用
我有一个直播,我想在我的HTA应用程序上播放。我已经尝试使用这个答案。 主要的
如何在当前文件夹中的hta中使用PowerShell在子文件夹中执行.bat文件?
我正在尝试执行位于hta文件所在当前文件夹子文件夹中的.bat文件。我在这里找到了文件夹结构>>文件夹结构下面是我的.hta代码的示例&...
hta / javascript如何执行具有相对路径的应用程序
我正在建立一个.hta(使用javascript),我想从中启动几个应用程序。但是,当我执行.hta时,我收到错误消息,找不到文件,这是代码:] >>