2

我正在尝试使用 loding bar 来增强我一直在研究的 hta。我想让加载栏运行,而另一个子正在执行。我不知道如何让两个潜艇同时运行。任何帮助表示赞赏。

   <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html> 
 <head> 
 <HTA:APPLICATION APPLICATIONNAME="Count - Progressbar - Table">
<script type="text/vbscript"> 
Class ProgressBar 
Public Sub Init() 
Dim NewDiv : Set NewDiv = Document.CreateElement("div") 
        NewDiv.innerHTML = "<div id='_progress' style='position:absolute;margin-top: 15px;top:0px;" & _ 
        "left:130px;height:230px;width:600px;background-color:orange;" & _ 
        "color:white;z-index:1000;display:none;'><div id='_LB0' style=" & _ 
        "'position:absolute;left:50%;top:50%;'><div style='position:absolute;" & _ 
        "font-family:arial;font-size:10px;color:green;left:-50px;top:-18px;'>" & _ 
        "<div id='_message'>Working&nbspHard H....</div><div id='_status'></div></div>" & _ 
        "<div style='position:absolute;left:-50px;top:-5px;font-size:1px;" & _ 
        "width:100px;height:10px;background:red'><div id='_LB1' " & _ 
        "style='position:absolute;left:0px;top:0px;font-size:1px;width:0px;" & _ 
        "height:10px;background:white'></div></div></div></div>" 
    Document.Body.AppendChild(newDiv) 
End Sub 

Public Sub Show() 
Dim p : Set p = Document.GetElementById("_progress") 
    With p.Style 
    .display = "" 
    End With 
End Sub 

Public Sub Hide() 
    Document.GetElementById("_progress").style.display = "none"

End Sub 

End Class 

</script> 

<script language="VBscript"> 

Sub Window_OnLoad 
    window.moveTo 200,200 
    window.resizeto 800,500
      Progress.init()
End Sub 


Function Reachable(strComputer) 
' On Error Resume Next 
Dim wshShell, fso, tfolder, tname, TempFile, results, retString, ts 
Const ForReading = 1, TemporaryFolder = 2 
Reachable = false 
Set wshShell = Createobject("wscript.shell") 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set tfolder = fso.GetSpecialFolder(TemporaryFolder) 
tname = fso.GetTempName 
TempFile = tfolder & tname 
wshShell.run "cmd /c ping -n 1 -w 10 " & strComputer & ">" & TempFile,0,true 
Set results = fso.GetFile(TempFile) 
Set ts = results.OpenAsTextStream(ForReading) 
    Do While ts.AtEndOfStream <> True 
    retString = ts.ReadLine 
        If instr(retString, "Reply") > 0 Then 
            Reachable = true 
        Exit Do 
        End If 
    Loop 
ts.Close 
results.delete 
Set ts = Nothing 
Set results = Nothing 
Set tfolder = Nothing 
Set fso = Nothing 
Set wshShell = Nothing 
End Function 

Dim Progress : Set Progress = New ProgressBar
Sub Table 
Progress.Show
For x = 0 to AvailableOptions.Options.Length - 1 
     If (AvailableOptions.Options(x).Selected) Then
         intCount = intCount + 1
     End If
Next
    DataArea.InnerHTML = ""
    strHTML = strHTML & "<table width='100%' border='0' cellspacing='1' class='tablesorter'>" 
    strHTML = strHTML & "<thead> " 
    strHTML = strHTML & "<tr>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Computer</STRONG></th>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Info A</STRONG></th>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Status</STRONG></th>" 
    strHTML = strHTML & "</tr>" 
    strHTML = strHTML & "</thead> " 
    strHTML = strHTML & "<tfoot> " 
    strHTML = strHTML & "<tr>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Computer</STRONG></th>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Info A</STRONG></th>" 
    strHTML = strHTML & "<th bgcolor = 'black'><font color = 'white'><b><STRONG>Status</STRONG></th>" 
    strHTML = strHTML & "</tr>" 
    strHTML = strHTML & "</tfoot> " 
    strHTML = strHTML & "<tbody> " 
         part = 1
         whole = intCount
          For i = 0 to AvailableOptions.Options.Length - 1 
            If (AvailableOptions.Options(i).Selected) Then
                strComputer = AvailableOptions.Options(i).Value    
            If part > whole Then 
                Document.GetElementById("_progress").style.display = "none" 

            Else 
                Document.GetElementById("_status").InnerText = Round(part / whole * 100) & "%" 
                Document.GetElementById("_LB1").Style.Width = Round(part / whole * 100) & "px"
                part=part+1
                    If Reachable(strComputer) Then 
                         strHTML = strHTML & "<tr>" 
                         strHTML = strHTML & "<td>" & strComputer & "</td>" 
                         strHTML = strHTML & "<td>Good</td>" 
                         strHTML = strHTML & "<td>ON</td>" 
                         strHTML = strHTML & "</tr>" 
                    Else 
                         strHTML = strHTML & "<tr>" 
                         strHTML = strHTML & "<td>" & strComputer & "</td>" 
                         strHTML = strHTML & "<td>Not so good</td>" 
                         strHTML = strHTML & "<td>OFF</td>" 
                         strHTML = strHTML & "</tr>" 
                    End If
            End If

     End If 

Next

strHTML = strHTML & "</tbody>" 
strHTML = strHTML & "</table>" 
strHTML = strHTML & intCount
Progress.Hide
DataArea.InnerHTML = strHTML
End Sub 

 </script> 
  </head> 
<body bgcolor="white"> 
    <select size="14" name="AvailableOptions" style="width:100" multiple="multiple" > 
    <option value="PC01">PC01</option> 
    <option value="PC02">PC02</option> 
    <option value="PC03">PC03</option> 
    <option value="PC04">PC04</option> 
    <option value="PC05">PC05</option> 
    <option value="PC06">PC06</option> 
    <option value="PC07">PC07</option> 
    <option value="PC08">PC08</option> 
    <option value="PC09">PC09</option> 
    <option value="PC10">PC10</option> 
    <option value="PC11">PC11</option> 
    <option value="PC12">PC12</option> 
    <option value="PC13">PC13</option> 
    <option value="PC14">PC14</option> 
</select> 

<div id="table" style='overflow:auto;position:absolute;margin-top: 15px;top:0px;left:130px;height:230px;width:600px;background-color:orange;z-index:1000;display:block;'> 
    TABLE 
    <p><span id="DataArea"></span></p> 
    <input type="button"  class="button" value="Table" style="width:70" onClick="VBScript:Table"> 
</div> 


</body> 
</html>
4

2 回答 2

3

考虑使用WshShell.Exec而不是WshShell.Run.

Exec将立即返回,在后台运行进程,让您在等待完成的同时完成其他操作(例如更新进度)ping

Run在进程退出之前不会返回,这允许您同步运行脚本和程序。

于 2010-11-20T15:20:28.557 回答
1

鉴于您的代码:

wshShell.run "cmd /c ping -n 1 -w 10 " & strComputer & ">" & TempFile,0,true  
Set results = fso.GetFile(TempFile)   
Set ts = results.OpenAsTextStream(ForReading)   
    Do While ts.AtEndOfStream <> True   
    retString = ts.ReadLine   
        If instr(retString, "Reply") > 0 Then   
            Reachable = true   
        Exit Do   
        End If   
    Loop   
ts.Close   

Exec可能是更好的选择,因为它允许您在ping代码仍在运行时捕获命令的输出。

执行方法

于 2010-12-02T11:07:28.100 回答