gpt4 book ai didi

windows - 从 HTA 中启动批处理文件

转载 作者:可可西里 更新时间:2023-11-01 10:43:13 25 4
gpt4 key购买 nike

我正在尝试从 HTA 文件中启动一个批处理文件。批处理文件的启动似乎正常启动(或至少相关的 CMD 提示),但批处理稍后关闭,大约需要 5 分钟。在 CMD 进程运行的短暂时刻,HTA 窗口似乎暂停,然后在 CMD 进程结束后立即关闭。 HTA 的其他所有功能均正常运行。

目标是让 HTA 在后台(隐藏)启动批处理文件,并且在处理批处理文件时对 HTA 没有影响。批处理文件完成并退出后,HTA 将启动一个包含用户信息的新 HTA。

这是我的 HTA,它运行不正常...

<html>
<head>
<style>
body { background:#fff url('../_dependencies/welcome.jpg') no-repeat center center fixed; color:#000; margin:25px; padding:0; }
div#gap { height:306px; }
div#buttons { padding-right:12px; position:absolute; right:0; }
</style>
<title>Installer</title>
<script language="vbscript">
Sub Window_OnLoad
Set Shell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sPath = Shell.ExpandEnvironmentStrings("%curdir%")
Continue = Chr(34) & sPath & "_install.cmd" & Chr(34)
Shell.Run Continue,0,True
CompName = Shell.ExpandEnvironmentStrings("%computername%")
Const ForAppending = 8
textFile = sPath & "_Logs\" & CompName & ".upgraded.txt"
If Not objFSO.FileExists(textFile) Then
Set objTextFile = objFSO.CreateTextFile(textFile, True)
objTextFile.Close
End If
Set objTextFile = objFSO.opentextfile(textFile,ForAppending)
objTextFile.WriteLine("Upgrade complete on this computer." & vbCrLf & Now())
objTextFile.Close
Set textFile = Nothing
self.close()
End Sub
</script>
<script language="javascript">
window.resizeTo(620,365);
window.moveTo((screen.width-620)/2,(screen.height-365)/2);
</script>
<hta:application applicationname="Installer" border="none" caption="no" id="objnotitlebar" innerborder="no" maximizebutton="no" minimizebutton="no" scroll="no" showintaskbar="no" singleinstance="yes" systemmenu="no">
</head>
<body>
<div id="gap"><img src="../_dependencies/waiting.gif" /></div>
<div id="buttons"></div>
</body>
</html>

最佳答案

Windows 不提供环境变量 %curdir%。它的扩展会产生一个文字字符串 %curdir%,因此命令提示符可能会立即关闭,因为找不到文件 %curdir%_install.cmd。您的意思是 %cd% 吗?该变量仅在 CMD 中可用。

你真的想首先从当前工作目录运行脚本吗?我会说您的意思更有可能是从与 HTA 相同的目录运行批处理文件。该位置可以这样确定:

dir = objFSO.GetParentFolderName(Replace(document.location.href, "file:///", ""))
sPath = objFSO.GetFolder(dir).Path

如果这对改变线路没有帮助

Shell.Run Continue,0,True

进入这个:

Shell.Run "%COMSPEC% /k " & Continue, 1, True

使用 cmd/k 运行批处理脚本会在(尝试的)脚本执行后保持命令提示符打开,因此您可以查看是否有任何错误。

关于windows - 从 HTA 中启动批处理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39853340/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com