<?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="http://forum.script-coding.com/extern.php?action=feed&amp;tid=13575&amp;type=atom" />
	<updated>2024-01-31T23:54:59Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=13575</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160197#p160197" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Xameleon пишет:</cite><blockquote></blockquote></div><p>Отлично то что нужно большое спасибо .:)<br />Но есть маленький минус не получается сверху добавить другой скрипт например &quot;On Error Resume Next&quot;.<br />А точнее хочется чтоб была защита от повторного запуска этого скрипта.<br />Так сказать сделать последний штрих .</p>]]></content>
			<author>
				<name><![CDATA[zcccz]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43530</uri>
			</author>
			<updated>2024-01-31T23:54:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160197#p160197</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160196#p160196" />
			<content type="html"><![CDATA[<p>...<br /></p><div class="codebox"><pre><code>
Option Explicit
Dim arrProcessNames
Dim strProcessName
Dim strWqlQuery
Dim colEvents 
Dim objWshShell

arrProcessNames = Array(&quot;calc1.exe&quot;,&quot;calc2.exe&quot;,&quot;calc3.exe&quot;)
Set objWshShell = CreateObject(&quot;WScript.Shell&quot;)
strWqlQuery = &quot;SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; AND (TargetInstance.Name = &#039;&quot; &amp; Join(arrProcessNames, &quot;&#039; OR TargetInstance.Name = &#039;&quot;) &amp; &quot;&#039;)&quot;
Set colEvents = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;).ExecNotificationQuery(strWqlQuery)

Do 
	With colEvents.NextEvent
		&#039;если процесс запускается
		If .Path_.Class = &quot;__InstanceCreationEvent&quot; Then
			objWshShell.Run &quot;taskkill /f /IM notepad.exe&quot;, 0
		&#039;если процесс завершается
		ElseIf .Path_.Class = &quot;__InstanceDeletionEvent&quot; Then
			objWshShell.Run &quot;notepad.exe&quot;
		End If
	End With
Loop
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2024-01-31T22:05:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160196#p160196</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160175#p160175" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Xameleon пишет:</cite><blockquote><p>В примере моего кода это реализовано.</p></blockquote></div><p>Ну первое черное окно которое показывает какой процесс открылся потом закрылся .Пробую WshShell.Run &quot;taskkill /f /IM notepad.exe&quot;, 0 просит WshShell.Run&nbsp; и много какие моменты.<br />А тот код который дал он работает совершенно по другому .<br />Если вы сможете изменить код который я дал очень буду признателен . <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[zcccz]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43530</uri>
			</author>
			<updated>2024-01-31T18:21:01Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160175#p160175</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160136#p160136" />
			<content type="html"><![CDATA[<p><strong>zcccz</strong>, так а что вам мешает использовать тот код, который я привёл в примере ? Вы спросили: <br /></p><div class="quotebox"><blockquote><p>можно ли сделать так чтоб срабатывало не только один &quot;calc.exe&quot; а несколько?</p></blockquote></div><p>В примере моего кода это реализовано.</p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2024-01-31T14:47:46Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160136#p160136</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160108#p160108" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Xameleon пишет:</cite><blockquote><p><strong>zcccz</strong>, приветствую ! Да, без проблем.</p></blockquote></div><p>Спасибо конечно но вы не тот код изменили .<br />Мне нужно именно этот изменить .<br /></p><div class="codebox"><pre><code>Set WSHShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
Const ProcName = &quot;calc.exe&quot;
Set colEvents = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;).ExecNotificationQuery( _
  &quot;SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; &quot; &amp; _
  &quot;AND TargetInstance.Name = &#039;&quot; &amp; ProcName &amp; &quot;&#039;&quot;)
Do 
 With colEvents.NextEvent
  &#039;если процесс запускается
  If .Path_.Class = &quot;__InstanceCreationEvent&quot; Then
       WshShell.Run &quot;taskkill /f /IM notepad.exe&quot;, 0
  &#039;если процесс завершается
  ElseIf .Path_.Class = &quot;__InstanceDeletionEvent&quot; Then
     WshShell.Run &quot;notepad.exe&quot;
  End If
 End With
Loop</code></pre></div><p>А ваш пробую и совершенно не то получается. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[zcccz]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43530</uri>
			</author>
			<updated>2024-01-30T00:41:31Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160108#p160108</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160107#p160107" />
			<content type="html"><![CDATA[<p><strong>zcccz</strong>, приветствую ! Да, без проблем.</p><div class="codebox"><pre><code>
Option Explicit
Dim arrProcessNames
Dim strProcessName
Dim strWqlQuery
Dim colEvents 

RunInConsoleMode()

arrProcessNames = Array(&quot;calc.exe&quot;,&quot;calculator.exe&quot;,&quot;win32calc.exe&quot;,&quot;notepad.exe&quot;)
strWqlQuery = &quot;SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; AND (TargetInstance.Name = &#039;&quot; &amp; Join(arrProcessNames, &quot;&#039; OR TargetInstance.Name = &#039;&quot;) &amp; &quot;&#039;)&quot;
Set colEvents = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;).ExecNotificationQuery(strWqlQuery)

Do 
	With colEvents.NextEvent
		&#039;если процесс запускается
		If .Path_.Class = &quot;__InstanceCreationEvent&quot; Then
			Wsh.Echo &quot;Process &quot; &amp;  .TargetInstance.Name &amp; &quot;[&quot; &amp; .TargetInstance.ProcessId &amp; &quot;] created&quot;
		&#039;если процесс завершается
		ElseIf .Path_.Class = &quot;__InstanceDeletionEvent&quot; Then
			Wsh.Echo &quot;Process &quot; &amp;  .TargetInstance.Name &amp; &quot;[&quot; &amp; .TargetInstance.ProcessId &amp; &quot;] terminated&quot;
		End If
	End With
Loop

Sub RunInConsoleMode()
	If InStr(1,WScript.FullName,&quot;cscript.exe&quot;) &lt; 1 Then
		CreateObject(&quot;WScript.Shell&quot;).Run(&quot;cscript //nologo &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot;&quot;)
		WScript.Quit
	End if
End Sub
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2024-01-29T19:26:28Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160107#p160107</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=160064#p160064" />
			<content type="html"><![CDATA[<p><strong>Xameleon</strong><br />Здравствуйте мне очень понравился код но можно ли сделать так чтоб срабатывало не только один &quot;calc.exe&quot; а несколько?<br /> <span style="color: red"><strong>Н</strong></span>апример &quot;calc.exe&quot;,&quot;calc2.exe&quot;,&quot;calc3.exe&quot;<span style="color: red"><strong>.</strong></span></p><br /><div class="codebox"><pre><code>Set WSHShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
Const ProcName = &quot;calc.exe&quot;
Set colEvents = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;).ExecNotificationQuery( _
  &quot;SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; &quot; &amp; _
  &quot;AND TargetInstance.Name = &#039;&quot; &amp; ProcName &amp; &quot;&#039;&quot;)
Do 
 With colEvents.NextEvent
  &#039;если процесс запускается
  If .Path_.Class = &quot;__InstanceCreationEvent&quot; Then
       WshShell.Run &quot;taskkill /f /IM notepad.exe&quot;, 0
  &#039;если процесс завершается
  ElseIf .Path_.Class = &quot;__InstanceDeletionEvent&quot; Then
     WshShell.Run &quot;notepad.exe&quot;
  End If
 End With
Loop</code></pre></div>]]></content>
			<author>
				<name><![CDATA[zcccz]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=43530</uri>
			</author>
			<updated>2024-01-26T11:20:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=160064#p160064</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124391#p124391" />
			<content type="html"><![CDATA[<p>Спасибо всем кто откликнулся, решил всетаки использовать свой первоначальный скрипт с ключем запуска //T: 35500 теперь все отрабатывает как надо !</p>]]></content>
			<author>
				<name><![CDATA[astra95]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=39161</uri>
			</author>
			<updated>2018-04-02T06:04:55Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124391#p124391</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124380#p124380" />
			<content type="html"><![CDATA[<p><strong>svoboden</strong>, озадачился непонятным явлением. Запустил Ваш скрипт у себя на Win 10. Работает то нормально, то нестабильно. Периодически не реагирует на запуск калькулятора. Хотя всё написано просто и понятно и кода то пара строк. К сожалению, в будни времени изучить не было, решил в выходные разобраться. Оказалось на Win 10 при запуске <strong>calc.exe</strong>, попеременно стартует то процесс <strong>calc.exe</strong>, то <strong>calculator.exe</strong>, хотя&nbsp; на экране визуально запускается одно и тоже приложение. Вот же ж микрософтовцы намудрили.</p><p>Решил отладиться на таком коде и тут же увидел в чём дело.<br /></p><div class="codebox"><pre><code>
EnableConsoleMode()

Set colEvents = GetObject(&quot;winmgmts:\\.\Root\CIMV2&quot;).ExecNotificationQuery( _
	&quot;SELECT * FROM &quot; &amp; _
		&quot;__InstanceCreationEvent WITHIN 1 &quot; &amp; _
	&quot;WHERE &quot; &amp; _ 
		&quot;TargetInstance ISA &#039;Win32_Process&#039;&quot;)
Do
	With colEvents.NextEvent
		WScript.Echo .TargetInstance.Name
	End With
Loop
	
Sub EnableConsoleMode()
	If InStr(1,WScript.FullName,&quot;cscript.exe&quot;) &lt; 1 Then
		CreateObject(&quot;WScript.Shell&quot;).Run(&quot;cscript //nologo &quot;&quot;&quot; &amp; WScript.ScriptFullName &amp; &quot;&quot;&quot;&quot;)
		WScript.Quit
	End if
End Sub
</code></pre></div><p><span class="postimg"><img src="https://i.imgur.com/43oYFQ1.png" alt="https://i.imgur.com/43oYFQ1.png" /></span></p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2018-04-01T17:39:57Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124380#p124380</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124337#p124337" />
			<content type="html"><![CDATA[<p><strong>astra95</strong>, изначальный запуск - это не самая большая проблема. Ваш вопрос изначально сложный, т.к. не понятно, как должен вести себя скрипт, если вы откроете, например, блокнот, когда запущен калькулятор.<br /></p><div class="quotebox"><cite>astra95 пишет:</cite><blockquote><p>Все таки скрипт не отрабатывает как нужно при длительном простое</p></blockquote></div><p>Если скрипт автоматически закрывается, то посмотрите, стоит ли галочка: &quot;Остановить сценарий после указанного числа секунд&quot; в параметрах сервера сценариев.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2018-03-30T14:47:25Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124337#p124337</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124316#p124316" />
			<content type="html"><![CDATA[<p><strong>svoboden</strong><br />Я понял какк он отробатывает, получаеться он отслеживает сам диспетчер задач. Попробую его приминить к своему процессу, спасибо.<br />Все отробатывает, но не хватает изначального запуска процесса хотелось бы сделать это в одном скрипте, если можете помогите пожалуйста !</p><p>Все таки скрипт не отрабатывает как нужно при длительном простое, при открытии calc.exe&nbsp; не закрываеться notepad.exe, за то ликвидируеться сам скрипт !</p>]]></content>
			<author>
				<name><![CDATA[astra95]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=39161</uri>
			</author>
			<updated>2018-03-29T10:59:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124316#p124316</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124309#p124309" />
			<content type="html"><![CDATA[<p><strong>Xameleon</strong><br />В том то и дел что мой вариант хоть и не полноценный запускает процесс, а этот вариант нет !</p><p><strong>svoboden</strong><br />Честно сказать я тоже интерпритировал работу скрипта так же как и <strong>Xameleon</strong>. Как же он тогда отрабатывает ?</p>]]></content>
			<author>
				<name><![CDATA[astra95]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=39161</uri>
			</author>
			<updated>2018-03-29T06:30:12Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124309#p124309</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124304#p124304" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>astra95 пишет:</cite><blockquote><p>но не запускает блокнот!</p></blockquote></div><p>А он и не должен его запускать, если не закроется процесс calc.exe.</p>]]></content>
			<author>
				<name><![CDATA[svoboden]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=34280</uri>
			</author>
			<updated>2018-03-28T20:29:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124304#p124304</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124295#p124295" />
			<content type="html"><![CDATA[<p><strong>astra95</strong>, а приложение калькулятора [calc.exe] Вы при этом запустили ?</p><p>Такой вариант скрипта, как приведён выше, требует, чтобы <strong>calc.exe</strong> был запущен после запуска скрипта (Т.е если calc.exe был запущен до запуска скрипта, то уже условие не сработает, т.к скрипт мониторит именно появление новых процессов и игнорирует старые.)</p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2018-03-28T11:42:21Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124295#p124295</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Скрипт который мониторит процесс]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=124291#p124291" />
			<content type="html"><![CDATA[<p><strong>svoboden</strong><br />Спасибо за ответ, но не работает, решил попробовать ваш пример не меняя ничего, скрипт запускаеться без проблем но не запускает блокнот!</p>]]></content>
			<author>
				<name><![CDATA[astra95]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=39161</uri>
			</author>
			<updated>2018-03-28T07:47:09Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=124291#p124291</id>
		</entry>
</feed>
