復制代碼代碼如下:
do while true
set WshShell = WScript.CreateObject("WScript.Shell")
IF WshShell.AppActivate("D:/") Then
MsgBox "ok"
wscript.quit
End If
loop
試都不要試,就知道這段代碼是錯誤的。因為WshShell.AppActivate考慮的是窗體的Caption中包含的字符或字符串,你用WshShell.AppActivate("D:/")這個,就是說窗體Caption里要包含"D:/"這個字符串??赡愦蜷_D盤看看,是這樣的嗎?都是“本地磁盤(D:)”。如果有卷標,那更說不準。所以應該寫成WshShell.AppActivate("(D:)"),考慮到內存節約的問題,應該這樣寫: set WshShell = WScript.CreateObject("WScript.Shell") do IF WshShell.AppActivate("(D:)") Then MsgBox "ok" wscript.quit End If loop