0

一部のサーバーにpingを実行して結果を出力するVBScriptがあります(このPastebinの完全なコード)。スクリプトの一部には、「お待ちください」というメッセージが表示された IE ウィンドウが表示されますが、何らかの理由で 2 つの IE ウィンドウが開いています (そして、以下のコードで希望どおりにデータが取り込まれています) Quit。脚本。

これが私に問題を引き起こしている機能です。1行目( objExplorer.Navigate)はリクエスト通りにウィンドウを開いているようですが、その前にSet objExplorer = CreateObject("InternetExplorer.Application")もウィンドウを開いています。

これを止める方法を知っている人はいますか?ありがとう。

' Display the progress box
Set objExplorer = CreateObject("InternetExplorer.Application")

display_progress(objExplorer)
main() ' Do stuff, see Pastebin for full code
close_progress(objExplorer)
output_results() ' Show user the results, see Pastebin for full code

Private Function display_progress(objExplorer)

    objExplorer.Navigate "about:blank"
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Left = 600
    objExplorer.Top = 374
    objExplorer.Width = 400
    objExplorer.Height = 152
    objExplorer.Visible = 1

    Dim strText, strButton

    strText = "<div id=""text""><p>Please wait, servers are being pinged.</p><p>Results will be displayed as soon as they are ready.</p></div>"
    strButton = "<div id=""buttons""><input type=""button"" name=""submit"" value=""Cancel"" onclick=""window.open('', '_self', ''); window.close();"" /><div class=""clear""></div></div>"

    objExplorer.Document.Body.Style.Font = "11pt 'Halvetica'"
    objExplorer.Document.Body.Style.Cursor = "wait"
    objExplorer.Document.Title = "Server ping script"
    objExplorer.Document.Body.InnerHTML = strStyle & strText & strButton    

End Function

Private Function close_progress(objExplorer)

    objExplorer.Document.Body.Style.Cursor = "default"
    objExplorer.Quit

End Function
4

2 に答える 2

0

force_cScriptあなたの関数が内部で呼び出されるのはFor..NextなぜですかMain?この関数は、スクリプトが開始されていない場合はスクリプトを再起動するだけですが、最初とIE オブジェクトの作成前にCScript.exe1 回だけ呼び出すだけで十分です。

Call force_cScript()
Set objExplorer = CreateObject("InternetExplorer.Application")
'...
于 2013-04-04T16:45:12.723 に答える
0

デビッド、コードの 'wscript.quit' (14 行目) の前に次のステートメントを含めて見てもらえますか?

Set objexplorer = nothing

また、関数「force_cscript」で、オブジェクト objshell を使用してから「wscript.quit」を使用していることもわかりました。オブジェクトを作成する場合は、スクリプトを終了する前に、何も設定しないか null 値に設定してください。そのため、関数「force_cscript」では、「wscript.quit」の前に次のステートメントを含めます。

Set objshell = nothing

これを行わないと、オブジェクトはバックグラウンドで実行され続けます。スクリプトを実行するたびに、オブジェクトがバックグラウンドで引き続きアクティブになるため、コンピューターは遅くなります。

于 2013-04-03T19:26:32.193 に答える