<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; HTA: Sleep для HTA / WSC]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=16019&amp;type=atom" />
	<updated>2021-01-24T22:36:14Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=16019</id>
		<entry>
			<title type="html"><![CDATA[Re: HTA: Sleep для HTA / WSC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145415#p145415" />
			<content type="html"><![CDATA[<p>Да, именно так.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2021-01-24T22:36:14Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145415#p145415</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: HTA: Sleep для HTA / WSC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145414#p145414" />
			<content type="html"><![CDATA[<p><strong>alexii</strong>, да, но если я правильно помню, то это опять же трансляция WSH объекта из одного процесса в другой (т.е их уже как минимум 2), что мне не очень нравится.</p>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2021-01-24T20:51:13Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145414#p145414</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: HTA: Sleep для HTA / WSC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145411#p145411" />
			<content type="html"><![CDATA[<p>Что-то же было: <a href="http://forum.script-coding.com/viewtopic.php?id=4196">JScript: Создание окна, а также трансляция WScript в HTA</a>.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2021-01-24T19:41:50Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145411#p145411</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[HTA: Sleep для HTA / WSC]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145388#p145388" />
			<content type="html"><![CDATA[<p>Когда-то давно потребовалась функция Sleep для WSC. Гугление привело только к такому <a href="https://stackoverflow.com/questions/16865430/sleep-routine-for-hta-scripts">результату</a>. Но предложенные решения либо требовали запуска сторонних процессов либо админских прав. Ни то ни другое меня особо не устроило и я собрал свой вариант. Сейчас наткнулся на него и решил, пускай на форуме тоже будет. Мало ли кому-то пригодится. </p><p>Интересно, а какими альтернативами пользуетесь вы в таких случаях ?</p><p><strong>Код для JS:</strong><br /></p><div class="codebox"><pre><code>
// Initializing sleep function
var sleep = (function(){
	var evt = GetObject(&#039;winmgmts:root\\CIMV2&#039;).ExecNotificationQuery(
		&#039;SELECT Milliseconds FROM __InstanceModificationEvent WITHIN 10000 \
		WHERE TargetInstance ISA &quot;Win32_LocalTime&quot; AND TargetInstance.Year &lt; 0&#039;
	)
	return function(milliseconds){
		try {evt.NextEvent(milliseconds)} catch(e){}
	}
})()

// Testing
var d = new Date();
sleep(3000);
WSH.Echo(new Date() - d)
</code></pre></div><p><strong>Код для VBS:</strong><br /></p><div class="codebox"><pre><code>
&#039; Class initialization and creating Sleep as instance for future calls
Class clsSleep
	Private objEvent
	Private Sub Class_Initialize()
		Set objEvent = GetObject(&quot;winmgmts:root\CIMV2&quot;).ExecNotificationQuery( _
		&quot;SELECT Milliseconds FROM __InstanceModificationEvent WITHIN 10000&quot; &amp; _
		&quot;WHERE TargetInstance ISA &#039;Win32_LocalTime&#039; AND TargetInstance.Year &lt; 0&quot;)
	End Sub
	Public Default Sub [](Milliseconds)
		On Error Resume Next
		objEvent.NextEvent(Milliseconds)
	End Sub
End Class
Dim Sleep:Set Sleep = new clsSleep

&#039; Testing
Dim sngStartTime
sngStartTime = Timer

Sleep 3000

MsgBox Int((Timer - sngStartTime) * 1000)
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2021-01-24T11:49:46Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145388#p145388</id>
		</entry>
</feed>
