我正在尝试从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>发布于 2016-10-05 17:12:18
因此,经过一些故障排除后,批处理脚本中的问题是一个配置错误的开始语句。
“削减战略武器条约”声明如下:
@start /b /min /wait "upgradeinstaller.exe" /silent /noreboot我把它改成了这个
@start /b /min /wait "Upgrade Installer" "upgradeinstaller.exe" /silent /noreboot显然,我需要将标题添加到start命令中,否则start命令认为第一个引用的文本是标题,然后应用开关启动,这是不起作用的。
发布于 2016-10-04 14:06:06
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运行批处理脚本将保持命令提示符的打开,因此您可以看到是否有任何错误。
https://stackoverflow.com/questions/39853340
复制相似问题