<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=4866&amp;type=atom" />
	<updated>2010-08-26T17:17:09Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=4866</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=38935#p38935" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>armenxxx1 пишет:</cite><blockquote><p>Почему такие хорошие решения проблем, не идут в разделе <strong>Windows Script Host (VBScript, JScript, HTA)</strong></p></blockquote></div><p>Если речь о <strong>коллекции</strong>, то в ней уже есть примеры создания подписок на системные события, причём и синхронного (как в данном случае), и асинхронного типов. По-моему, нет только варианта для подписки полусинхронного типа.</p><p>Попутно сделаю ещё пару замечаний по обсуждаемому сценарию.<br />1. Добавить нужную привилегию можно непосредственно в операторе подключения к WMI-пространству.<br />То есть пару вырыжений<br /></p><div class="quotebox"><blockquote><p>Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2&quot;)<br />objWMIService.Security_.Privileges.AddAsString &quot;SeDebugPrivilege&quot;, True</p></blockquote></div><p>можно заменить на одно<br /></p><div class="quotebox"><blockquote><p>Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate<strong><span style="color: green">,(Debug)</span></strong>}!\\.\root\CIMV2&quot;)</p></blockquote></div><p>2. Имя контролируемого процесса можно задать непосредственно в операторе создания подписки.<br />То есть выражение<br /></p><div class="quotebox"><blockquote><p>Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039;&quot;)</p></blockquote></div><p>можно немного усложнить<br /></p><div class="quotebox"><blockquote><p>Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; <strong><span style="color: green">AND TargetInstance.Name=&#039;cmd.exe&#039;</span></strong>&quot;)</p></blockquote></div><p>В итоге получим такой вариант сценария:<br /></p><div class="codebox"><pre><code>strComputer = &quot;.&quot;
Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate,(Debug)}!\\.\root\CIMV2&quot;)
Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039; AND TargetInstance.Name=&#039;cmd.exe&#039;&quot;)
Do
    Set objReceivedEvent = objEvents.NextEvent
    objReceivedEvent.TargetInstance.Terminate
Loop</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Dmitrii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=13351</uri>
			</author>
			<updated>2010-08-26T17:17:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=38935#p38935</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=38911#p38911" />
			<content type="html"><![CDATA[<p>Почему такие хорошие решения проблем, не идут в разделе <strong>Windows Script Host (VBScript, JScript, HTA)</strong> <img src="//forum.script-coding.com/img/smilies/hmm.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[armenxxx1]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26102</uri>
			</author>
			<updated>2010-08-25T20:45:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=38911#p38911</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=38908#p38908" />
			<content type="html"><![CDATA[<p>По-моему, так рациональнее:<br /></p><div class="codebox"><pre><code>strComputer = &quot;.&quot;
Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2&quot;)
objWMIService.Security_.privileges.addasstring &quot;sedebugprivilege&quot;, true
Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA &#039;Win32_Process&#039;&quot;)
Do
    Set objReceivedEvent = objEvents.NextEvent
    If StrComp(objReceivedEvent.TargetInstance.Name, &quot;cmd.exe&quot;, vbTextCompare) = 0 Then objReceivedEvent.TargetInstance.Terminate
Loop</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Dmitrii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=13351</uri>
			</author>
			<updated>2010-08-25T19:30:33Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=38908#p38908</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=38891#p38891" />
			<content type="html"><![CDATA[<p>Задачу решил, надо было быть чуть-чуть внимательнее</p><div class="codebox"><pre><code>strComputer = &quot;.&quot;
Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2&quot;)
Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE (TargetInstance ISA &#039;Win32_Process&#039;)&quot;)
Do While(True)
    Set objReceivedEvent = objEvents.NextEvent
    objWMIService.Security_.privileges.addasstring &quot;sedebugprivilege&quot;, true
    For Each objItem In objWMIService.ExecQuery(&quot;SELECT * FROM Win32_Process&quot;)
    If objItem.name = &quot;cmd.exe&quot; Then
    objItem.Terminate
    End If
    Next
Loop</code></pre></div>]]></content>
			<author>
				<name><![CDATA[neitan]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26191</uri>
			</author>
			<updated>2010-08-25T13:57:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=38891#p38891</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: Терминирование процессов Win32_Process Terminate()(решено)]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=38884#p38884" />
			<content type="html"><![CDATA[<p>Всем доброго времени суток! Проблема пустяковая но изучать wmi я начал только несколько дней назад так что заранее извиняюсь за неграмотность:)<br />Данный скрипт должен отслеживать и завершать все новые процессы cmd.exe. Если процесс запущен под пользователем от которого запущен скрипт проблем нет, но если скрипт запускать под другим пользователем(Администратор) то &quot;Terminate&quot; возвращает 0, но процесс не завершает. На <a href="http://msdn.microsoft.com/en-us/library/aa393907">http://msdn.microsoft.com/en-us/library/aa393907</a> нашел что необходимо сделать чтобы завершить процесс другого пользователя:<br /></p><div class="quotebox"><blockquote><p>To terminate a process that you do not own, enable the SeDebugPrivilege privilege. In VBScript, you can enable this privilege with the following lines of code:<br />Copy</p><p>Set objLoc = createobject(&quot;wbemscripting.swbemlocator&quot;)<br />objLoc.Security_.privileges.addasstring &quot;sedebugprivilege&quot;, true</p></blockquote></div><p>Но как это применить не понял.</p><div class="codebox"><pre><code>strComputer = &quot;.&quot;
Set objWMIService = Getobject(&quot;winmgmts:{impersonationLevel=impersonate}!\\.\root\CIMV2&quot;)
Set objEvents = objWMIService.ExecNotificationQuery(&quot;SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE (TargetInstance ISA &#039;Win32_Process&#039;)&quot;)
Do While(True)
    Set objReceivedEvent = objEvents.NextEvent
    For Each objItem In objWMIService.ExecQuery(&quot;SELECT * FROM Win32_Process&quot;)
    If objItem.name = &quot;cmd.exe&quot; Then
    objItem.Terminate
    End If
    Next
Loop</code></pre></div>]]></content>
			<author>
				<name><![CDATA[neitan]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26191</uri>
			</author>
			<updated>2010-08-25T08:25:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=38884#p38884</id>
		</entry>
</feed>
