同时运行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 Hard 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>
I am trying to enhance an hta i've been working on for a while with a loding bar. I want to make the loading bar running while the other sub is being executed. I don't know how to make both subs run at the same time. Any help is appreciated.
<!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 Hard 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑使用
WshShell.Exec
而不是WshShell.Run
。Exec
将立即返回,在后台运行该进程,允许您在等待ping
完成的同时完成其他操作(例如更新进度)。Run
在进程退出之前不会返回,这允许您同步运行脚本和程序。Consider using
WshShell.Exec
instead ofWshShell.Run
.Exec
will return immediately, running the process in the back ground allowing you to complete other actions (such as updating the progress) whilst waiting for theping
to complete.Run
does not return until the process has exited and this allows you to run scripts and programs synchronously.给定您的代码:
Exec
可能是更好的选择,因为它允许您在代码仍在运行时捕获ping
命令的输出。请参阅执行方法
Given your code:
Exec
mightbe a better choice as it allows you to capture the output of theping
command while your code is still running.See Exec Method