<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBScript: как из скрипта изменить приоритет его процесса]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=3547</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=3547&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBScript: как из скрипта изменить приоритет его процесса».]]></description>
		<lastBuildDate>Tue, 18 Aug 2009 06:38:35 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBScript: как из скрипта изменить приоритет его процесса]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=27253#p27253</link>
			<description><![CDATA[<div class="codebox"><pre><code>Option Explicit

&#039; Перечень констант, соответствующих предопределённым приоритетам.
&#039; Взято с: http://msdn.microsoft.com/en-us/library/aa393587(VS.85).aspx
&#039;
&#039; Замечание оттуда же относительно установки приоритета «Real Time»:
&#039; To set the priority to Realtime, the caller must have SeIncreaseBasePriorityPrivilege (SE_INC_BASE_PRIORITY_PRIVILEGE).
&#039; Without this privilege, the highest the priority can be set to is High Priority.
Const IDLE_PRIORITY_CLASS         = &amp;H0040
Const BELOW_NORMAL_PRIORITY_CLASS = &amp;H4000
Const NORMAL_PRIORITY_CLASS       = &amp;H0020
Const ABOVE_NORMAL_PRIORITY_CLASS = &amp;H8000
Const HIGH_PRIORITY_CLASS         = &amp;H0080
Const REAL_TIME_PRIORITY_CLASS    = &amp;H0100


Dim i

&#039; Меняем приоритет процесса скрипта, например, на «Idle»:
GetObject(&quot;winmgmts:root\cimv2:Win32_Process.Handle=&#039;&quot; &amp; CStr(GetScriptProcessID()) &amp; &quot;&#039;&quot;).SetPriority IDLE_PRIORITY_CLASS

&#039;-----------------------------------------------------------------------------
&#039; Здесь будет Ваш код. Мы же, в данном случае, для демонстрации просто имитируем нагрузку, не используя WScript.Sleep:
i = 1
Do
    i = i + 1
    i = i - 1
Loop
&#039;-----------------------------------------------------------------------------

WScript.Quit 0
&#039;=============================================================================

&#039;=============================================================================
&#039; Получение идентификатора процесса (PID) скрипта.
&#039; Подробности в: http://forum.script-coding.com/viewtopic.php?pid=15930#p15930
&#039;=============================================================================
Function GetScriptProcessID()
    With WScript.CreateObject(&quot;WScript.Shell&quot;).Exec(&quot;&quot;&quot;mshta.exe&quot;&quot; &quot; &amp; _
        &quot;&quot;&quot;&lt;HTML&gt;&lt;HEAD&gt;&lt;HTA:APPLICATION APPLICATIONNAME=&#039;GetParentPID&#039; &quot; &amp; _
        &quot;WINDOWSTATE=&#039;minimize&#039; SHOWINTASKBAR=&#039;no&#039;&lt;/HEAD&gt;&lt;/HTML&gt;&quot;&quot;&quot;)
        
        GetScriptProcessID = GetObject(&quot;winmgmts:\\.\root\CIMV2:Win32_Process.Handle=&#039;&quot; &amp; CStr(.ProcessID) &amp;&quot;&#039;&quot;).ParentProcessID
        .Terminate
    End With
End Function
&#039;=============================================================================</code></pre></div><p>Отдельное спасибо коллегам <strong>Carno</strong>, <strong>MikeSh</strong>, <strong>VSVLAD</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (alexii)]]></author>
			<pubDate>Tue, 18 Aug 2009 06:38:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=27253#p27253</guid>
		</item>
	</channel>
</rss>
