我有一个使用 WshShell.Exec 获取 Windows 版本的 html 应用程序 (HTA)。我wmic os get Caption
用来获取特定版本,它在命令行和批处理脚本中运行良好。我还测试了我调用的方式WshShell.Exec
,它可以与其他命令(即echo Windows 2008
)一起正常工作。当我尝试将这些东西组合在一起时,就会出现问题,Exec 似乎只是冻结了。你能推荐一个解决这个问题的方法吗?这是我的代码:
Function GetWinVersion
'Returns 2008, XP, or 7
set WshShell = CreateObject("WScript.Shell")
set oExec = WshShell.Exec("wmic os get Caption")
do while oExec.Status = 0
'I added this very busy wait, though it doesn't seem to help
'Would sleep if it was available in an hta
loop
While oExec.StdOut.AtEndOfStream <> True
thisLine = oExec.StdOut.ReadLine
'MsgBox "Found line: " & thisLine
if InStr(thisLine, "2008") > 0 then
GetWinVersion=2008
Exit Function
elseif InStr(thisLine, "XP") > 0 then
GetWinVersion=XP
Exit Function
elseif InStr(thisLine, "Windows 7") > 0 then
GetWinVersion=7
Exit Function
end if
Wend
MsgBox "Error parsing output of wmic os get Caption"
self.Close
End Function