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的輸出? –