<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS & WMI: асинхронный поиск файлов]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5741&amp;type=atom" />
	<updated>2011-05-12T09:54:17Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5741</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=48329#p48329" />
			<content type="html"><![CDATA[<p>Вот что у меня вышло, но этот код не работает<br /></p><div class="codebox"><pre><code>Dim sFilter, fCount, objItems, sFiles, sPath
Dim objShell, objWMI, objSink, f
sFilter = &quot;*.log;*.bak&quot;
sFiles = Array()

Set objShell = CreateObject(&quot;Shell.Application&quot;)
Set objWMI = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;)
Set objSink = WScript.CreateObject(&quot;WbemScripting.SWbemSink&quot;, &quot;Sink_&quot;)

&#039;[Выполнение асинхронного запроса] 
objWMI.ExecQueryAsync objSink, &quot;SELECT * FROM Win32_Directory&quot;

&#039;цикл ожидания, пока выполнится запрос
f = false
While Not bdone
    WScript.Sleep 100
Wend

WScript.Echo &quot;Finished&quot;
objSink.Cancel
Set objSink = Nothing
Set objWMI = Nothing
Set objShell = Nothing
WScript.Quit

&#039;[Обнаружение экземпляра объекта (каталога)]
&#039;------------------------------------------------------------------------
Function Sink_OnObjectReady(objWbemObject, objWbemAsyncContext)
    
    On Error resume Next
    objItems = objShell.NameSpace(objWbemObject.Name).Items()
    If Err.Number &lt;&gt; 0 Then  &#039;Exit Function
    WScript.Echo Err.Number
    End If

    &#039;[Фильтрация элементов каталога по маске]
    &#039;----------------------------------------------------------------
    fCount = objItems.Count
    If fCount = 0 Then
    Exit Function 
    End If
    
    objItems.Filter 192, sFilter
    
    fCount = objItems.Count
    If fCount = 0 Then  
    Exit Function 
    End If    
    &#039;[Формирование строки путей найденных файлов]
    &#039;----------------------------------------------------------------
    For i = 0 to fCount -1
        sPath = objItems.Item(i).Path
        sFiles = sFiles + sPath
    Next

End Function

&#039;[Завершение запроса]
&#039;------------------------------------------------------------------------
Function Sink_OnCompleted(iHResult, objWbemErrorObject, objWbemAsyncContext)
    f = true  &#039;флаг завершения запроса
    If UBound(sFiles) = -1 Then
        WScript.Echo &quot;--Ничего не найдено--&quot;
    Else
        WScript.Echo &quot;Найденные файлы: &quot; &amp; VbCrLf &amp; sFiles
    End If
End Function</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Patrik]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26913</uri>
			</author>
			<updated>2011-05-12T09:54:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=48329#p48329</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47797#p47797" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>
    If fCount = 0 Then  &#039;Exit Function 
    End If
    Exit Function
    
    objItems.Filter 64+128, sFilter
    
    fCount = objItems.Count
    If fCount = 0 Then  &#039;Exit Function 
    End If
    Exit Function</code></pre></div><p>Исправьте на<br /></p><div class="codebox"><pre><code>
    If fCount = 0 Then
        Exit Function 
    End If
    
    objItems.Filter 64+128, sFilter
    
    fCount = objItems.Count
    If fCount = 0 Then
        Exit Function 
    End If</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2011-04-25T09:33:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47797#p47797</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47796#p47796" />
			<content type="html"><![CDATA[<p>Еще не понятно с функцией&nbsp; function Sink_OnObjectReady(objWbemObject, objWbemAsyncContext).<br />Вот что у меня получилось:<br /></p><div class="codebox"><pre><code>Function Sink_OnObjectReady(objWbemObject, objWbemAsyncContext)
     On Error resume Next
     objItems = objShell.NameSpace(objWbemObject.Name).Items()
    
    &#039;[Фильтрация элементов каталога по маске]
    &#039;----------------------------------------------------------------
    fCount = objItems.Count
    If fCount = 0 Then  &#039;Exit Function 
    End If
    Exit Function
    
    objItems.Filter 64+128, sFilter
    
    fCount = objItems.Count
    If fCount = 0 Then  &#039;Exit Function 
    End If
    Exit Function    
    &#039;[Формирование строки путей найденных файлов]
    &#039;----------------------------------------------------------------
    For i=0 To i&lt;fCount
        sPath = objItems.Item(i).Path
        sFiles = sFiles + sPath
        i=i+1
    Next

End Function</code></pre></div><p>Где у меня ошибка?</p>]]></content>
			<author>
				<name><![CDATA[Patrik]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26913</uri>
			</author>
			<updated>2011-04-25T09:21:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47796#p47796</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47792#p47792" />
			<content type="html"><![CDATA[<p>Вышеприведенная строка на js избыточна, достаточно было бы написать <strong>var sFilter = &#039;*.log;*.wlg;*.err;*.bak&#039;;</strong></p><p>Вот перевод:<br /></p><div class="codebox"><pre><code>
Dim sFilter
sFilter = &quot;*.log;*.wlg;*.err;*.bak&quot;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2011-04-24T18:49:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47792#p47792</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47791#p47791" />
			<content type="html"><![CDATA[<p>Совершенно верно.<br />Как преобразовать строку:<br /></p><div class="codebox"><pre><code> var sFilter = String(&#039;*.log;*.wlg;*.err;*.bak&#039;);</code></pre></div><p>на VBS ?</p>]]></content>
			<author>
				<name><![CDATA[Patrik]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26913</uri>
			</author>
			<updated>2011-04-24T18:42:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47791#p47791</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47782#p47782" />
			<content type="html"><![CDATA[<p><strong>alexii</strong>, я так понял, что <strong>Patrik</strong> хочет перевести <a href="http://forum.script-coding.com/viewtopic.php?pid=40040#p40040">код от <strong>Poltergeyst</strong></a> с JS на VBS. </p><p><strong>Patrik</strong>, Вы можете вызывать JSкод из VBS. И где вызывают трудности в переводе?</p>]]></content>
			<author>
				<name><![CDATA[JSmаn]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24434</uri>
			</author>
			<updated>2011-04-23T05:23:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47782#p47782</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47779#p47779" />
			<content type="html"><![CDATA[<p><strong>Patrik</strong>, всё равно не понятно. Вот же оно: <a href="http://forum.script-coding.com/viewtopic.php?id=5008">Серый форум / JScript &amp; WMI: асинхронный поиск файлов</a>, всё доступно.</p><p>P.S. Если опять не то, и Вы пришли сюда по ссылке с поисковика, то приведите эту ссылку, дабы можно было установить её происхождение и куда она попала.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-04-22T21:04:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47779#p47779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47772#p47772" />
			<content type="html"><![CDATA[<p>Можно выложить этот скрипт на VBS&nbsp; ?<br />Пытаюсь сам переконвертировать, но не получается...</p>]]></content>
			<author>
				<name><![CDATA[Patrik]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26913</uri>
			</author>
			<updated>2011-04-22T08:46:54Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47772#p47772</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47755#p47755" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Patrik пишет:</cite><blockquote><p>Можно выложить на VBS асинхронный поиск файлов созданный пользователем Poltergeyst&nbsp; ?</p></blockquote></div><p>Перефразируйте. Не очень понятно, что Вы хотите.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-04-21T16:16:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47755#p47755</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS & WMI: асинхронный поиск файлов]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=47754#p47754" />
			<content type="html"><![CDATA[<p>Можно выложить на VBS асинхронный поиск файлов созданный пользователем Poltergeyst&nbsp; ?<br />Конвертирую сам, но чтото у меня не получается с функцией <br /></p><div class="codebox"><pre><code>function Sink_OnCompleted(iHResult, objWbemErrorObject, objWbemAsyncContext)</code></pre></div><p>Выдает ошибку <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p><div class="codebox"><pre><code>Function Sink_OnObjectReady(objWbemObject, objWbemAsyncContext)
    
    On Error resume Next
    Set objItems = objShell.NameSpace(String(objWbemObject.Name)).Items()
    If Err.Number &lt;&gt; 0 Then
    WScript.Echo Err.Number
    End If
    
    
    &#039;[Фильтрация элементов каталога по маске]
    &#039;----------------------------------------------------------------
    Set fCount = objItems.Count
    If fCount = 0 Then  WScript.Echo &quot;Выход 1&quot; 
    &#039;Exit Function
    End If
    
    objItems.Filter(64+128, sFilter)
    Set fCount = objItems.Count
    If fCount = 0 Then  WScript.Echo &quot;Выход 2&quot; 
    &#039;Exit Function
    End If    
    &#039;[Формирование строки путей найденных файлов]
    &#039;----------------------------------------------------------------
    For i=0 To i&lt;fCount
        sPath = objItems.Item(i).Path
        sFiles = sFiles + sPath + VbCrLf
        i=i+1
    Next

End Function</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Patrik]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26913</uri>
			</author>
			<updated>2011-04-21T15:46:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=47754#p47754</id>
		</entry>
</feed>
