<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; HTA/VBScript: Проблемы синтаксиса...]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7218&amp;type=atom" />
	<updated>2012-05-15T08:45:43Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7218</id>
		<entry>
			<title type="html"><![CDATA[HTA/VBScript: Проблемы синтаксиса...]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=60345#p60345" />
			<content type="html"><![CDATA[<p>Коллеги, приветствую !<br />Есть следующий код: (асинхронный мультипинг)<br /></p><div class="codebox"><pre><code>&lt;html&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1251&quot;&gt;
&lt;style type=&quot;text/css&quot;&gt;
*{font-family:tahoma;font-size:11px;padding:0px 0px 0px 0px;margin-bottom:0px;margin-top:0px;margin-left:0px;margin-right:0px;}
table{cellspacing=&quot;0&quot;;cellpadding=&quot;0&quot;;}
table td{padding:0px;cellpadding=&quot;0&quot;;} 
&lt;/style&gt;
&lt;body style=&quot;overflow-x:auto; overflow-y:auto&quot;&gt;
&lt;table id=&quot;result&quot;&gt;
&lt;/table&gt;
&lt;OBJECT id=&quot;objSink&quot; style=&quot;display:none;&quot; classid=&quot;clsid:75718C9A-F029-11D1-A1AC-00C04FB6C223&quot;&gt;&lt;/OBJECT&gt;

&lt;SCRIPT LANGUAGE=VBScript&gt;
Document.Title=&quot;ЗАПУЩЕНО - &quot; &amp; Now
window.resizeto 300,100
Public objDictionary,arrComputers,bDone,IDTimer,strFirst
arrComputers = Array(&quot;195.219.232.84&quot;,&quot;213.140.114.17&quot;,&quot;94.230.136.33&quot;)

Sub window_onload()
strFirst=1
Call Pinger()
End Sub

Sub Pinger()
Window.clearInterval(IDtimer)
Set objDictionary = CreateObject(&quot;Scripting.Dictionary&quot;)
Set objService = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;)
&#039;Set objSink = CreateObject(&quot;WbemScripting.SWbemSink&quot;, &quot;Sink_&quot;)
bDone = False
For Each strComputer In arrComputers
  Set objContext = CreateObject(&quot;WbemScripting.SWbemNamedValueSet&quot;)
  objContext.Add &quot;hostname&quot;, strComputer
  objService.ExecQueryAsync objSink, &quot;select * from Win32_PingStatus where address =&#039;&quot; &amp; strComputer &amp; &quot;&#039;&quot;, , , , objContext
Next
If strFirst=1 Then
IDtimer = window.setInterval(&quot;vbscript: call First()&quot;, 500)
Else
IDtimer = window.setInterval(&quot;vbscript: call Waiter()&quot;, 500)
End If
End Sub

Sub First()
If objDictionary.Count=Ubound(arrComputers)+1 Then
Window.clearInterval(IDtimer)
objSink.Cancel
ret=SortDictionary(objDictionary, 1)

For r=0 to Document.GetElementByID(&quot;result&quot;).Rows.Length-1
Document.GetElementByID(&quot;result&quot;).deleteRow
Next

Document.GetElementByID(&quot;result&quot;).insertRow
With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
    .innerHtml = &quot;Адрес&quot;
    .align=&quot;center&quot;
End With
With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
    .innerHtml = &quot;Время&lt;BR&gt;ответа&quot;
    .align=&quot;center&quot;
End With
With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
    .innerHtml = &quot;Пропавшие&lt;BR&gt;пакеты&quot;
    .align=&quot;center&quot;
End With
With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
    .innerHtml = &quot;Последний&lt;BR&gt;обрыв&quot;
    .align=&quot;center&quot;
End With

For Each strKey in objDictionary.Keys
Document.GetElementByID(&quot;result&quot;).insertRow
rowIndex=Document.GetElementByID(&quot;result&quot;).Rows.Length-1
With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
strBad=0
If Left(objDictionary.Item(strKey),2)=&quot;On&quot; Then
    .style.backgroundcolor=&quot;Green&quot;
        .innerHtml = &quot;&amp;nbsp;&quot; &amp; strKey &amp; &quot;&amp;nbsp;&quot;
Else
    .style.backgroundcolor=&quot;Red&quot;
        .innerHtml = &quot;&amp;nbsp;&quot; &amp; strKey &amp; &quot;&amp;nbsp;&quot;
    strBad=1
End If
End With

Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell

With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).Cells(1)
    .innerHtml = &quot;&amp;nbsp;&quot; &amp; Mid(objDictionary.Item(strKey),4,Len(objDictionary.Item(strKey))-3)
    .align=&quot;center&quot;
End With

With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
        .align=&quot;center&quot;
If strBad=0 Then
        .innerHtml = 0
Else
        .innerHtml = 1
End If
End With

With Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell
        .align=&quot;center&quot;
    .style.whitespace=&quot;nowrap&quot;
If strBad=0 Then
        .innerHtml = &quot;&amp;nbsp;&quot;
Else
        .innerHtml = Now
End If
End With

Next
objDictionary.RemoveAll
strFirst=0
IDtimer = window.setInterval(&quot;vbscript: call Pinger()&quot;, 300)
End If
End Sub


Sub Waiter()
If objDictionary.Count=Ubound(arrComputers)+1 Then
Window.clearInterval(IDtimer)
objSink.Cancel
ret=SortDictionary(objDictionary, 1)

&#039;For r=0 to Document.GetElementByID(&quot;result&quot;).Rows.Length-1
&#039;Document.GetElementByID(&quot;result&quot;).deleteRow
&#039;Next

&#039;Document.GetElementByID(&quot;result&quot;).insertRow
&#039;Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell.innerHtml = &quot;Адрес&quot;
&#039;Document.GetElementByID(&quot;result&quot;).Rows(rowIndex).insertCell.innerHtml = &quot;Время&lt;BR&gt;ответа&quot;

row=1

For Each strKey in objDictionary.Keys

With Document.GetElementByID(&quot;result&quot;).Rows(row).Cells(0)

If Left(objDictionary.Item(strKey),2)=&quot;On&quot; Then
    .style.backgroundcolor=&quot;Green&quot;
        .innerHtml = &quot;&amp;nbsp;&quot; &amp; strKey &amp; &quot;&amp;nbsp;&quot;
Else
    .style.backgroundcolor=&quot;Red&quot;
        .innerHtml = &quot;&amp;nbsp;&quot; &amp; strKey &amp; &quot;&amp;nbsp;&quot;

Document.GetElementByID(&quot;result&quot;).Rows(row).Cells(2).innerHTML=CInt(Document.GetElementByID(&quot;result&quot;).Rows(row).Cells(2).innerHTML)+1
Document.GetElementByID(&quot;result&quot;).Rows(row).Cells(3).innerHTML=Now

End If
End With
Document.GetElementByID(&quot;result&quot;).Rows(row).Cells(1).innerHtml = &quot;&amp;nbsp;&quot; &amp; Mid(objDictionary.Item(strKey),4,Len(objDictionary.Item(strKey))-3)
row=row+1
Next
objDictionary.RemoveAll
IDtimer = window.setInterval(&quot;vbscript: Pinger()&quot;, 300)
End If
End Sub

Sub objSink_OnObjectReady(objWbemObject, objWbemAsyncContext)
strComputer = objWbemAsyncContext.Item(&quot;hostname&quot;)
res=&quot;&quot;
  Select Case objWbemObject.StatusCode
    Case 0
      res = &quot;On &quot; &amp; objWbemObject.ResponseTime 
    Case Else
      res = &quot;Off&quot;
  End Select
objDictionary.Add strComputer, res
End Sub


Function SortDictionary(objDict, intSort)

    Const dictKey  = 1
    Const dictItem = 2

    Dim strDict()
    Dim objKey
    Dim strKey,strItem
    Dim X,Y,Z

    Z = objDict.Count

    If Z &gt; 1 Then
      ReDim strDict(Z,2)
      X = 0

      For Each objKey In objDict
          strDict(X,dictKey)  = CStr(objKey)
          strDict(X,dictItem) = CStr(objDict(objKey))
          X = X + 1
      Next

      For X = 0 To (Z - 2)
        For Y = X To (Z - 1)
          If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) &gt; 0 Then
              strKey  = strDict(X,dictKey)
              strItem = strDict(X,dictItem)
              strDict(X,dictKey)  = strDict(Y,dictKey)
              strDict(X,dictItem) = strDict(Y,dictItem)
              strDict(Y,dictKey)  = strKey
              strDict(Y,dictItem) = strItem
          End If
        Next
      Next

      objDict.RemoveAll

      For X = 0 To (Z - 1)
        objDict.Add strDict(X,dictKey), strDict(X,dictItem)
      Next

    End If

  End Function

&lt;/SCRIPT&gt;

&lt;/body&gt;
&lt;/html&gt;</code></pre></div><p>В среде Win XP SP3 x86 работает замечательно, но в Win7 Ultimate x64 в строке №33<br /></p><div class="codebox"><pre><code>  objService.ExecQueryAsync objSink, &quot;select * from Win32_PingStatus where address =&#039;&quot; &amp; strComputer &amp; &quot;&#039;&quot;, , , , objContext</code></pre></div><p>выдаёт <br /></p><div class="quotebox"><blockquote><p>Generic failure</p></blockquote></div><p>WTF ?</p>]]></content>
			<author>
				<name><![CDATA[Евген]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25253</uri>
			</author>
			<updated>2012-05-15T08:45:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=60345#p60345</id>
		</entry>
</feed>
