<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Необходимо слежение за службой]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=5137&amp;type=atom" />
	<updated>2010-11-18T07:05:05Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=5137</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Необходимо слежение за службой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=41890#p41890" />
			<content type="html"><![CDATA[<p>Дико извиняюсь за задержку, но был занят...<br />вот код.<br /></p><div class="codebox"><pre><code>strComputer=&quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)
Set SINK = WScript.CreateObject(&quot;WbemScripting.SWbemSink&quot;,&quot;SINK_&quot;)
objWMIService.ExecNotificationQueryAsync SINK, &quot;SELECT * FROM __InstanceModificationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Service&#039;&quot;

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)


Do while 1=1   
    WScript.Sleep 1000
Loop

&#039;******************************************************************************
        
Sub SINK_OnObjectReady(objLatestEvent, objAsyncContext)

If objLatestEvent.TargetInstance.Name=&quot;Browser&quot; Then
Set objFile = fso.OpenTextFile(&quot;monitor.log&quot;, 8, True) 
objFile.WriteLine  Now &amp; objLatestEvent.TargetInstance.State
objFile.Close
End If
End Sub</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Евген]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25253</uri>
			</author>
			<updated>2010-11-18T07:05:05Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=41890#p41890</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Необходимо слежение за службой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=41759#p41759" />
			<content type="html"><![CDATA[<p>Надо отслеживать события (Events), асинхронно...<br />как освобожусь, нацарапаю...&nbsp; &nbsp;пока занят...</p>]]></content>
			<author>
				<name><![CDATA[Евген]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25253</uri>
			</author>
			<updated>2010-11-16T11:11:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=41759#p41759</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Необходимо слежение за службой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=41756#p41756" />
			<content type="html"><![CDATA[<p>Получаем состояние службы &quot;MSSQLSERVER&quot;(на основе заготовки из WMICodeCreator):<br /></p><div class="codebox"><pre><code>option explicit
Dim strComputer, objWMIService, colServiceList, objService
strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp; strComputer &amp; &quot;\root\CIMV2&quot;)
Set colServiceList = objWMIService.ExecQuery(&quot;select State, Status from Win32_Service where Name=&#039;MSSQLSERVER&#039;&quot;)
For Each objService in colServiceList
 Wscript.Echo objService.Name &amp; &quot;=&gt; State: &quot; &amp; objService.State &amp; &quot;; Status: &quot; &amp; objService.Status
Next</code></pre></div><p>Единственное, не могу сказать какие значения будут у State&amp;Status когда сервис не отвечает(не знаю как смоделировать ситуацию :). Кстати, программа сама является сервисом или &quot;сервис&quot; стартует другое ПО(например, как srvany)? Т.е. когда &quot;режим остается Started, при этом служба перестает работать&quot;(&quot;Started&quot; я так понимаю в оснастке управления службами? После нажатия F5 он не меняется?) исполняемый файл службы в процессах остаётся или исчезает?</p><p><a href="http://msdn.microsoft.com/en-us/library/aa394418(VS.85).aspx">MSDN: Win32_Service Class</a></p>]]></content>
			<author>
				<name><![CDATA[BeS Yara]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=25643</uri>
			</author>
			<updated>2010-11-16T09:53:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=41756#p41756</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Необходимо слежение за службой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=41376#p41376" />
			<content type="html"><![CDATA[<p>А при чём тут «.Started»? Это говорит лишь о том, что служба <em>была</em> запущена. Каково свойство «.State» службы:<br /></p><div class="codebox"><pre><code>wmic.exe service &lt;имя службы&gt; get State /value</code></pre></div><p>в тот момент, когда «она … отваливается»?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2010-11-09T10:20:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=41376#p41376</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Необходимо слежение за службой]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=41364#p41364" />
			<content type="html"><![CDATA[<p>Добрый день. Подскажите, как реализовать слежение за службой (она иногда отваливается, но режим остается Started, при этом служба перестает работать), то есть нужно как-то проверить, именно работает она или нет. Заранее спасибо.</p>]]></content>
			<author>
				<name><![CDATA[ZonTiara]]></name>
			</author>
			<updated>2010-11-09T06:44:37Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=41364#p41364</id>
		</entry>
</feed>
