1
我有一个使用WshShell.Exec获取Windows版本的html应用程序(HTA)。我使用wmic os get Caption
来获取特定版本,该版本在命令行和批处理脚本中可以正常工作。我也测试了我打电话的方式WshShell.Exec
,并且它可以很好地与其他命令(即echo Windows 2008
)一起工作。当我尝试将Exec似乎刚刚冻结的这些东西结合起来时,就会出现问题。你能推荐一个解决方法吗?这里是我的代码:为什么VBScript有时会阻塞在WshShell.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
+1这使我的代码工作。谢谢。任何想法为什么Exec阻止?我听说这在其他地方也会引起问题,并且想知道为什么我不会再被抓到。 – Jared
不,我得到了相同的结果,请尝试检查StdErr的输出? –