<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS  диалог открытия файла не работает на Windows 7]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6192&amp;type=atom" />
	<updated>2011-10-25T12:09:35Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6192</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52902#p52902" />
			<content type="html"><![CDATA[<p>Точно так же:<br /></p><div class="codebox"><pre><code>Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
…
strCurrentDirectory = WshShell.CurrentDirectory
…
&lt;код по Dialog Open File&gt;
…
WshShell.CurrentDirectory = strCurrentDirectory
…</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-10-25T12:09:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52902#p52902</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52899#p52899" />
			<content type="html"><![CDATA[<p>Это понятно. <br /></p><div class="quotebox"><blockquote><p>Вызов диалога меняет текущую рабочую папку скрипта. Как следствие перестают читаться файли настроек и т.д. &quot;нацеленые&quot; на как бы &quot;текущую&quot; папку. Как этот победить? Есть команда смены папки?</p></blockquote></div><p>Получить текущую папку труда не составляет. Как вернуться обратно потом?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2011-10-25T11:31:29Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52899#p52899</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52896#p52896" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>Set WshShell = CreateObject(&quot;WScript.Shell&quot;)
…WshShell.CurrentDirectory…</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-10-25T11:24:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52896#p52896</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=52892#p52892" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)<br />WScript.Echo WshShell.CurrentDirectory</p></blockquote></div><p>А если через HTA нужно сделать?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2011-10-25T10:12:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=52892#p52892</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51790#p51790" />
			<content type="html"><![CDATA[<p>Приветствую всех. Захотелось поучаствовать в обсуждении. ) Использовал идею <strong>smaharbA</strong>. За что ему большое спасибо. ) Не так давно понадобилась такая же функция. В итоге собрал класс и WSC оболочку на него. Может кому то так удобнее будет.<br />Вышеописанных проблем с кодировкой вроде бы не заметил.</p><p>Ниже исходники + примеры</p><p><strong>Класс</strong><br /></p><div class="codebox"><pre><code>
Class clsOPTSHOLDLib
	Private WshExec, oDlg, ShellWindows, form_id, id, st, ShellWindow
	Private Sub Class_Initialize()
		On Error Resume Next
		Set ShellWindows = CreateObject(&quot;Shell.Application&quot;).Windows: Randomize: id = Clng(Rnd*100000)
		Set wshExec = CreateObject(&quot;WScript.Shell&quot;).Exec(&quot;mshta about:&quot;&quot;&lt;script&gt;moveTo(-1000,-1000);resizeTo(0,0);&lt;/script&gt;&quot; &amp;_
									&quot;&lt;hta:application showintaskbar=no /&gt;&quot; &amp;_
									&quot;&lt;object id=&quot; &amp; id &amp; &quot; classid=&#039;clsid:8856F961-340A-11D0-A96B-00C04FD705A2&#039;&gt;&lt;param name=RegisterAsBrowser value=1&gt;&lt;/object&gt;&quot; &amp;_
									&quot;&lt;object id=oDlg classid=&#039;clsid:3050F4E1-98B5-11CF-BB82-00AA00BDCE0B&#039;&gt;&lt;/object&gt;&quot;&quot;&quot;)
		st = Now
		Do
			For Each ShellWindow in ShellWindows 
				form_id = Clng(ShellWindow.id)
				if form_id = id Then 
					Set oDlg = ShellWindow.document.all.oDlg.Object
					Exit Sub
				End if
			Next
		Loop Until DateDiff(&quot;s&quot;,st,now) =&gt; 10
		On Error Goto 0
		if isEmpty(oDlg) Then Err.Raise vbObjectError, &quot;HtmlDlgHelper&quot;, &quot;Dialog creation failed.&quot;
	End Sub
	
	Public Property Get HtmlDlgHelper()
		Set HtmlDlgHelper = oDlg
	End Property
	
	Private Sub Class_Terminate()
		On Error Resume Next
		WshExec.Terminate()
	End Sub
End Class</code></pre></div><p><strong>Пример с использованием класса</strong><br /></p><div class="codebox"><pre><code>
Option Explicit

Dim OPTSHOLDLib, HtmlDlgHelper, ret
Set OPTSHOLDLib = New clsOPTSHOLDLib
Set HtmlDlgHelper = OPTSHOLDLib.HtmlDlgHelper

ret = HtmlDlgHelper.openfiledlg()

MsgBox ret</code></pre></div><p><strong>WSC (Windows Script Component)</strong><br /></p><div class="codebox"><pre><code>
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;component&gt;
&lt;?component error=&quot;true&quot; debug=&quot;true&quot;?&gt;
&lt;registration
	description=&quot;HtmlDlgHelper&quot;
	progid=&quot;HtmlDlgHelper.wsc&quot;
	version=&quot;1.00&quot;
	classid=&quot;{86376100-1f27-4d81-8328-8c6565096c0e}&quot;
&gt;
&lt;/registration&gt;

&lt;public&gt;
	&lt;property name=&quot;fonts&quot;&gt;
		&lt;get/&gt;
	&lt;/property&gt;
	&lt;method name=&quot;openfiledlg&quot;&gt;
		&lt;PARAMETER name=&quot;initFile&quot;/&gt;
		&lt;PARAMETER name=&quot;initDir&quot;/&gt;
		&lt;PARAMETER name=&quot;filter&quot;/&gt;
		&lt;PARAMETER name=&quot;title&quot;/&gt;
	&lt;/method&gt;
	&lt;method name=&quot;savefiledlg&quot;&gt;
		&lt;PARAMETER name=&quot;initFile&quot;/&gt;
		&lt;PARAMETER name=&quot;initDir&quot;/&gt;
		&lt;PARAMETER name=&quot;filter&quot;/&gt;
		&lt;PARAMETER name=&quot;title&quot;/&gt;
	&lt;/method&gt;
	&lt;method name=&quot;choosecolordlg&quot;&gt;
		&lt;PARAMETER name=&quot;initColor&quot;/&gt;
	&lt;/method&gt;
	&lt;method name=&quot;getCharset&quot;&gt;
		&lt;PARAMETER name=&quot;fontName&quot;/&gt;
	&lt;/method&gt;
	&lt;method name=&quot;openfiledlgex&quot;&gt;
		&lt;PARAMETER name=&quot;initFile&quot;/&gt;
		&lt;PARAMETER name=&quot;initDir&quot;/&gt;
		&lt;PARAMETER name=&quot;filter&quot;/&gt;
		&lt;PARAMETER name=&quot;initFilterIndex&quot;/&gt;
		&lt;PARAMETER name=&quot;title&quot;/&gt;
	&lt;/method&gt;
&lt;/public&gt;

&lt;script language=&quot;VBScript&quot;&gt;
&lt;![CDATA[
Option Explicit

Dim OPTSHOLDLib, HtmlDlgHelper
Set OPTSHOLDLib = New clsOPTSHOLDLib
Set HtmlDlgHelper = OPTSHOLDLib.HtmlDlgHelper

Class clsOPTSHOLDLib
	Private WshExec, oDlg, ShellWindows, form_id, id, st, ShellWindow
	Private Sub Class_Initialize()
		On Error Resume Next
		Set ShellWindows = CreateObject(&quot;Shell.Application&quot;).Windows: Randomize: id = Clng(Rnd*100000)
		Set wshExec = CreateObject(&quot;WScript.Shell&quot;).Exec(&quot;mshta about:&quot;&quot;&lt;script&gt;moveTo(-1000,-1000);resizeTo(0,0);&lt;/script&gt;&quot; &amp;_
									&quot;&lt;hta:application showintaskbar=no /&gt;&quot; &amp;_
									&quot;&lt;object id=&quot; &amp; id &amp; &quot; classid=&#039;clsid:8856F961-340A-11D0-A96B-00C04FD705A2&#039;&gt;&lt;param name=RegisterAsBrowser value=1&gt;&lt;/object&gt;&quot; &amp;_
									&quot;&lt;object id=oDlg classid=&#039;clsid:3050F4E1-98B5-11CF-BB82-00AA00BDCE0B&#039;&gt;&lt;/object&gt;&quot;&quot;&quot;)
		st = Now
		Do
			For Each ShellWindow in ShellWindows 
				form_id = Clng(ShellWindow.id)
				if form_id = id Then 
					Set oDlg = ShellWindow.document.all.oDlg.Object
					Exit Sub
				End if
			Next
		Loop Until DateDiff(&quot;s&quot;,st,now) =&gt; 10
		On Error Goto 0
		if isEmpty(oDlg) Then Err.Raise vbObjectError, &quot;HtmlDlgHelper&quot;, &quot;Dialog creation failed.&quot;
	End Sub
	
	Public Property Get HtmlDlgHelper()
		Set HtmlDlgHelper = oDlg
	End Property
	
	Private Sub Class_Terminate()
		On Error Resume Next
		WshExec.Terminate()
	End Sub
End Class

]]&gt;
&lt;/script&gt;
&lt;script language=&quot;JScript&quot;&gt;
&lt;![CDATA[

function get_fonts()
{
	return HtmlDlgHelper.fonts
}

function openfiledlg(initFile,initDir,filter,title)
{
	return HtmlDlgHelper.openfiledlg(initFile,initDir,filter,title)
}

function savefiledlg(initFile,initDir,filter,title)
{
	return HtmlDlgHelper.savefiledlg(initFile,initDir,filter,title)
}

function choosecolordlg(initColor)
{
	return HtmlDlgHelper.choosecolordlg(initColor)
}

function getCharset(fontName)
{
	return HtmlDlgHelper.getCharset(fontName)
}

function openfiledlgex(initFile,initDir,filter,initFilterIndex,title)
{
	return HtmlDlgHelper.openfiledlgex(initFile,initDir,filter,initFilterIndex,title)
}

]]&gt;
&lt;/script&gt;
	
&lt;/component&gt;</code></pre></div><p><strong>Пример использования WSC</strong></p><div class="codebox"><pre><code>
Option Explicit
Dim HtmlDlgHelper, ret
Set HtmlDlgHelper = GetObject(&quot;script:&quot; &amp; Left(WScript.ScriptFullName,InstrRev(WScript.ScriptFullName,&quot;\&quot;)) &amp; &quot;HtmlDlgHelper.wsc&quot;)
ret = HtmlDlgHelper.openfiledlg(&quot;&quot;,,&quot;Картинки (*.jpg;*.gif;*.png;*.bmp)|*.jpg;*.gif;*.png;*.bmp|Все файлы (*.*)|*.*&quot;,&quot;Выберите картинку...&quot;)
MsgBox ret</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Xameleon]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=8836</uri>
			</author>
			<updated>2011-09-23T18:20:43Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51790#p51790</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51719#p51719" />
			<content type="html"><![CDATA[<p>Спасибо</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2011-09-21T18:01:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51719#p51719</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51691#p51691" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Mat Skywalker пишет:</cite><blockquote><p>Есть команда смены папки?</p></blockquote></div><p><a href="http://msdn.microsoft.com/en-us/library/3cc5edzd(v=vs.85).aspx">CurrentDirectory Property</a></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-09-20T04:23:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51691#p51691</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51690#p51690" />
			<content type="html"><![CDATA[<p><span style="color: Green"><strong>Mat Skywalker</strong>, согласно <a href="http://forum.script-coding.com/rules.html#2.9.">§2.9</a> — такое здесь не публикуем. Я удалил из Вашего поста лишнее.</span></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-09-20T04:21:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51690#p51690</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51683#p51683" />
			<content type="html"><![CDATA[<p>Еще одни грабли с CommonDialog это лицензирование. При вызове диалога появляется сообщение навроде: &quot;Лицензирование верно не выполнено&quot;.<br />Вот <span style="color: Green"><strong>здесь была</strong></span> ссылка текст для реестра с лицензиями на большинство контролов VB:<br /></p><div class="codebox"><pre><code>REGEDIT
…</code></pre></div><p>Вот такой вопросец. Вызов диалога меняет текущую рабочую папку скрипта. Как следствие перестают читаться файли настроек и т.д. &quot;нацеленые&quot; на как бы &quot;текущую&quot; папку. Как этот победить? Есть команда смены папки?</p>]]></content>
			<author>
				<name><![CDATA[Mat Skywalker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26275</uri>
			</author>
			<updated>2011-09-19T17:16:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51683#p51683</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51536#p51536" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Rom5 пишет:</cite><blockquote><p>чтобы была возможность выбора не единственного файла, а множественный выбор</p></blockquote></div><p>Если речь о диалоге UserAccounts.CommonDialog, то у него есть свойство Flags, если устанавливаем = &amp;H0200 - получаем возможность выбрать несколько файлов.</p>]]></content>
			<author>
				<name><![CDATA[dab00]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27085</uri>
			</author>
			<updated>2011-09-15T13:49:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51536#p51536</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51535#p51535" />
			<content type="html"><![CDATA[<p>Коллеги, данный диалог можно ли вызвать так, чтобы была возможность выбора не единственного файла, а множественный выбор?<br />Этот нюанс мне довольно критичено, подскажите плз.</p>]]></content>
			<author>
				<name><![CDATA[Rom5]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=5724</uri>
			</author>
			<updated>2011-09-15T12:54:28Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51535#p51535</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51440#p51440" />
			<content type="html"><![CDATA[<p>Это не была шутка: <a href="http://forum.script-coding.com/rules.html#4.3.">§4.3</a>.</p><p>Какой именно пример? В <a href="http://forum.script-coding.com/viewtopic.php?pid=51389#p51389">приведённом коде</a> меняете MsgBox на присвоение значения переменной:<br /></p><div class="codebox"><pre><code>sPath2File = [Диалог].object.openfiledlg(&quot;C:\*.jpg;*.gif;*.png;*.bmp &quot;,,&quot;Картинки (*.jpg;*.gif;*.png;*.bmp)|*.jpg;*.gif;*.png;*.bmp|Все файлы (*.*)|*.*&quot;,&quot;Выберите картинку...&quot;)</code></pre></div><p>после закрытия окна:<br /></p><div class="codebox"><pre><code>[Документ].parentWindow.close()</code></pre></div><p>вписываете проверку, что не была нажата кнопка «Отмена», и пользуетесь полученным путём к файлу:<br /></p><div class="codebox"><pre><code>If Len(sPath2File) &lt;&gt; 0 Then
   &#039; Здесь Ваш код, например
   WScript.Echo sPath2File
End If</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-09-12T14:45:48Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51440#p51440</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51434#p51434" />
			<content type="html"><![CDATA[<p>Шутку понял <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Я неточно выразился, но всё же.<br />Хотелось бы пример такого кода.</p>]]></content>
			<author>
				<name><![CDATA[Rialto]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26530</uri>
			</author>
			<updated>2011-09-12T11:26:17Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51434#p51434</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51433#p51433" />
			<content type="html"><![CDATA[<p><strong>Rialto</strong>, можно.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-09-12T11:20:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51433#p51433</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS  диалог открытия файла не работает на Windows 7]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=51429#p51429" />
			<content type="html"><![CDATA[<p>Интересно, а можно ли переделать код, чтобы не выскакивал msgbox с полным путём файла ?</p>]]></content>
			<author>
				<name><![CDATA[Rialto]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26530</uri>
			</author>
			<updated>2011-09-12T07:40:16Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=51429#p51429</id>
		</entry>
</feed>
