<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBScript: как из скрипта изменить приоритет его процесса]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=3547&amp;type=atom" />
	<updated>2009-08-18T06:38:35Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=3547</id>
		<entry>
			<title type="html"><![CDATA[VBScript: как из скрипта изменить приоритет его процесса]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=27253#p27253" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2009-08-18T06:38:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=27253#p27253</id>
		</entry>
</feed>
