我不知道为什么我在此VBS代码的Set objShell =
语句中出错(在HTML中)。我正在为一款名为Doom的游戏开发.HTA启动器,该VBScript可以选择游戏并使用一些参数启动它。
Dim pwad, warp, skill, execDoom, execPwad, execWarp, execSkill, rep, fso, file, OpFScript, WScript, objShell
Set objShell = WScript.CreateObject("WScript.Shell")
Set pwad = document.GetElementById("inpFILE")
Set warp = document.GetElementById("inpMAP")
Set skill = document.GetElementById("inpSKILL")
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\ZDLRemastered\launcher\ScriptOpFile.txt", 1)
OpFScript = file.ReadAll
Function GetFileDlgEx(sIniDir,sFilter,sTitle)
Set oDlg = CreateObject("WScript.Shell").Exec("mshta.exe & OpFScript")
oDlg.StdIn.Write "var iniDir='" & sIniDir & "';var filter='" & sFilter & "';var title='" & sTitle & "';"
GetFileDlgEx = oDlg.StdOut.ReadAll
End Function
sFilter = "Doom Archive (*.wad)|*.wad|"
sTitle = "Select a Doom IWAD"
rep = GetFileDlgEx(Replace(sIniDir,"\","\\"),sFilter,sTitle)
execDoom = "C:\ZDLRemastered\gzdoom\gzdoom.exe -config C:\ZDLRemastered\gzdoom\gzconfig.ini -iwad "
execPwad = " -file "
execWarp = " -warp "
execSkill = " -skill "
objShell.Run execDoom & Chr(34) & rep & Chr(34) & execPwad & Chr(34) & pwad & Chr(34) & execWarp & Chr(34) & warp & Chr(34) & execSkill & Chr(34) & skill & Chr(34)
这是错误:
必要的对象:“--
答案 0 :(得分:0)
HTA在不同于常规VBScript的引擎中运行(mshta.exe
与wscript.exe
/ cscript.exe
)。 HTA引擎未提供内部WScript
对象,因此WScript.CreateObject()
或WScript.Sleep()
或WScript.Quit()
将不起作用。
但是,由于VBScript还具有全局函数CreateObject()
(即not the same as WScript.CreateObject()
),因此不需要内部对象来创建对象。
更改此:
Set objShell = WScript.CreateObject("WScript.Shell")
对此:
Set objShell = CreateObject("WScript.Shell")
问题将消失。