<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; Установка и настройка Google Chrome через VBS]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=14332&amp;type=atom" />
	<updated>2018-11-20T06:28:46Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=14332</id>
		<entry>
			<title type="html"><![CDATA[Re: Установка и настройка Google Chrome через VBS]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129911#p129911" />
			<content type="html"><![CDATA[<p><strong>cherfull22</strong><br />Приведенный код только определяет наличие Chrome.</p>]]></content>
			<author>
				<name><![CDATA[omegastripes]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29228</uri>
			</author>
			<updated>2018-11-20T06:28:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129911#p129911</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Установка и настройка Google Chrome через VBS]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129909#p129909" />
			<content type="html"><![CDATA[<p><strong>omegastripes</strong></p><p>Подскажите в данном коде расширение устанавливается из магазина&nbsp; браузера или как сторонний файл?? Есть ли возможность как из магазина установить ?</p>]]></content>
			<author>
				<name><![CDATA[cherfull22]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39640</uri>
			</author>
			<updated>2018-11-20T02:59:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129909#p129909</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Установка и настройка Google Chrome через VBS]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129907#p129907" />
			<content type="html"><![CDATA[<p>Для определения имеется ли Chrome на ПК или нет, можно использовать следующий код:<br /></p><div class="codebox"><pre><code>Option Explicit

Dim bFound, sChromePath, lChromeVersion

CheckChrome bFound, sChromePath, lChromeVersion
If bFound Then
	MsgBox &quot;Путь: &quot; &amp; sChromePath &amp; vbCrLf &amp; &quot;Версия: &quot; &amp; lChromeVersion
Else
	MsgBox &quot;Chrome не найден&quot;
End If


Sub CheckChrome(bFound, sChromePath, lChromeVersion)
	
	Dim sUrl, sPath, oWshShell, oWshExec, oStdOut, sContent
	
	bFound = False
	&#039; Проверка Chrome в установленных программах
	CheckChromeInstall bFound, sChromePath, lChromeVersion
	If Not bFound Then
		&#039; Проверка Chrome в стандартных папках
		CheckChromeFolders bFound, sChromePath, lChromeVersion
		If Not bFound Then Exit Sub
	End If
	
End Sub

Sub CheckChromeInstall(bFound, sChromePath, lChromeVersion)
	
	&#039; Проверка Chrome в установленных программах
	
	Const HKLM = &amp;H80000002 &#039; HKEY_LOCAL_MACHINE
	Dim oReg, sKey, aSubkeys, sSubkey, iRet, sValue, sInstallLocation, sVersion
	
	bFound = False
	Set oReg = GetObject(&quot;winmgmts://./root/default:StdRegProv&quot;)
	For Each sKey In Array(&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\&quot;, &quot;SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\&quot;)
		oReg.EnumKey HKLM, sKey, aSubkeys
		If Not IsNull(aSubkeys) Then
			For Each sSubkey In aSubkeys
				iRet = oReg.GetStringValue(HKLM, sKey &amp; sSubkey, &quot;DisplayName&quot;, sValue)
				If iRet &lt;&gt; 0 Then oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;QuietDisplayName&quot;, sValue
				If sValue = &quot;Google Chrome&quot; Then
					oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;InstallLocation&quot;, sInstallLocation
					oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;Version&quot;, sVersion
					Select Case True
						Case IsNull(sInstallLocation)
						Case sInstallLocation = &quot;&quot;
						Case Not CreateObject(&quot;Scripting.FileSystemObject&quot;).FileExists(sInstallLocation &amp; &quot;\chrome.exe&quot;)
						Case IsNull(sVersion)
						Case sVersion = &quot;&quot;
						Case Not IsNumeric(Split(sVersion, &quot;.&quot;, 2)(0))
						Case Else
							bFound = True
							sChromePath = sInstallLocation &amp; &quot;\chrome.exe&quot;
							lChromeVersion = CLng(Split(sVersion, &quot;.&quot;, 2)(0))
						Exit Sub
					End Select
				End If
			Next
		End If
	Next
	
End Sub

Sub CheckChromeFolders(bFound, sChromePath, lChromeVersion)
	
	&#039; Проверка Chrome в стандартных папках
	
	Dim oFolders, sFolder, sPath, lVersion
	
	bFound = False
	Set oFolders = CreateObject(&quot;Scripting.Dictionary&quot;)
	With CreateObject(&quot;WScript.Shell&quot;)
		oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;localappdata&quot;)) = &quot;&quot;
		oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programfiles&quot;)) = &quot;&quot;
		oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programfiles(x86)&quot;)) = &quot;&quot;
		oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programw6432&quot;)) = &quot;&quot;
		oFolders.Item(.ExpandEnvironmentStrings(&quot;%programfiles%&quot;)) = &quot;&quot;
		oFolders.Item(.ExpandEnvironmentStrings(&quot;%programfiles(x86)%&quot;)) = &quot;&quot;
	End With
	With CreateObject(&quot;Shell.Application&quot;)
		oFolders.Item(.Namespace(&amp;H26).Self.Path) = &quot;&quot;
		oFolders.Item(.Namespace(&amp;H2A).Self.Path) = &quot;&quot;
	End With
	For Each sFolder In oFolders
		sPath = sFolder &amp; &quot;\Google\Chrome\Application\chrome.exe&quot;
		If CreateObject(&quot;Scripting.FileSystemObject&quot;).FileExists(sPath) Then
			lVersion = GetFileVersion(sPath)
			If lVersion &lt;&gt; &quot;&quot; Then
				bFound = True
				sChromePath = sPath
				lChromeVersion = lVersion
				Exit Sub
			End If
		End If
	Next
	
End Sub

Function GetFileVersion(sPath)
	
	Dim oShell, oFolder, oFile, i, sName, sVersion, sFolderName, sFileName
	
	GetFileVersion = &quot;&quot;
	SplitFullPath sPath, sFolderName, sFileName
	Set oShell = CreateObject(&quot;Shell.Application&quot;)
	Set oFolder = oShell.Namespace(sFolderName)
	Set oFile = oFolder.ParseName(sFileName)
	For i = 0 To 511
		sName = oFolder.GetDetailsOf(oFolder.Items, i)
		If LCase(sName) = &quot;версия файла&quot; Or LCase(sName) = &quot;file version&quot; Then
			sVersion = oFolder.GetDetailsOf(oFile, i)
			Select Case True
				Case sVersion = &quot;&quot;
				Case Not IsNumeric(Split(sVersion, &quot;.&quot;, 2)(0))
				Case Else
					GetFileVersion = CLng(Split(sVersion, &quot;.&quot;, 2)(0))
					Exit Function
			End Select
			Exit Function
		End If
	Next
	
End Function

Sub SplitFullPath(sPath, sFolderName, sFileName)
	
	With CreateObject(&quot;Scripting.FileSystemObject&quot;)
		If Not .FileExists(sPath) Then Exit Sub
		sFolderName = .GetParentFoldername(sPath)
		sFileName = .GetFileName(sPath)
	End With
	
End Sub</code></pre></div><div class="fancy_spoiler_switcher"><div class="fancy_spoiler_switcher_header"><strong>+</strong>&nbsp;Небольшой оффтоп на тему Headless Chrome</div><div class="fancy_spoiler"><p>Раз уж тема коснулась Chrome, пожалуй, опубликую еще один небольшой кусок кода, разработанный вместе с представленным выше. Это пример использования Headless Chrome для получения HTML содержимого страниц. Вероятно, кому-то будет интересно, в качестве альтернативы IE, вопрос пока вроде не особо обсуждался.<br /></p><div class="codebox"><pre><code>Option Explicit

Dim oHeadlessChrome

Set oHeadlessChrome = New clsHeadlessChrome

If oHeadlessChrome.IsAvailable Then
	MsgBox oHeadlessChrome.GetContent(&quot;https://api.myip.com/&quot;)
Else
	MsgBox &quot;Headless Chrome недоступен&quot; 
End If

Class clsHeadlessChrome
	
	Private psChromePath, pbAvailable
	
	Private Sub Class_Initialize()
		
		Dim bFound, lChromeVersion
		
		CheckChrome bFound, psChromePath, lChromeVersion
		pbAvailable = bFound And (lChromeVersion &gt;= 59)
		
	End Sub
	
	Function GetContent(sUrl)
		
		Const BlankPage = &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;
		
		Dim oWshShell, oWshExec, oStdOut, sContent, sCmd
		
		GetContent = &quot;&quot;
		If Not pbAvailable Then Exit Function
		Set oWshShell = CreateObject(&quot;WScript.Shell&quot;)
		sCmd = &quot;&quot;&quot;&quot; &amp; psChromePath &amp; &quot;&quot;&quot; --headless --disable-gpu --dump-dom &quot; &amp; sUrl
		Set oWshExec = oWshShell.Exec(sCmd)
		Set oStdOut = oWshExec.StdOut
		sContent = oStdOut.ReadAll
		If Mid(sContent, 1, Len(BlankPage)) &lt;&gt; BlankPage Then GetContent = sContent
		
	End Function
	
	Public Property Get IsAvailable()
		
		IsAvailable = pbAvailable
		
	End Property
	
	Private Sub CheckChrome(bFound, sChromePath, lChromeVersion)
		
		Dim sUrl, sPath, oWshShell, oWshExec, oStdOut, sContent
		
		bFound = False
		&#039; Проверка Chrome в установленных программах
		CheckChromeInstall bFound, sChromePath, lChromeVersion
		If Not bFound Then
			&#039; Проверка Chrome в стандартных папках
			CheckChromeFolders bFound, sChromePath, lChromeVersion
		End If
		
	End Sub
	
	Private Sub CheckChromeInstall(bFound, sChromePath, lChromeVersion)
		
		&#039; Проверка Chrome в установленных программах
		
		Const HKLM = &amp;H80000002 &#039; HKEY_LOCAL_MACHINE
		Dim oReg, sKey, aSubkeys, sSubkey, iRet, sValue, sInstallLocation, sVersion
		
		bFound = False
		Set oReg = GetObject(&quot;winmgmts://./root/default:StdRegProv&quot;)
		For Each sKey In Array(&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\&quot;, &quot;SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\&quot;)
			oReg.EnumKey HKLM, sKey, aSubkeys
			If Not IsNull(aSubkeys) Then
				For Each sSubkey In aSubkeys
					iRet = oReg.GetStringValue(HKLM, sKey &amp; sSubkey, &quot;DisplayName&quot;, sValue)
					If iRet &lt;&gt; 0 Then oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;QuietDisplayName&quot;, sValue
					If sValue = &quot;Google Chrome&quot; Then
						oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;InstallLocation&quot;, sInstallLocation
						oReg.GetStringValue HKLM, sKey &amp; sSubkey, &quot;Version&quot;, sVersion
						Select Case True
							Case IsNull(sInstallLocation)
							Case sInstallLocation = &quot;&quot;
							Case Not CreateObject(&quot;Scripting.FileSystemObject&quot;).FileExists(sInstallLocation &amp; &quot;\chrome.exe&quot;)
							Case IsNull(sVersion)
							Case sVersion = &quot;&quot;
							Case Not IsNumeric(Split(sVersion, &quot;.&quot;, 2)(0))
							Case Else
								bFound = True
								sChromePath = sInstallLocation &amp; &quot;\chrome.exe&quot;
								lChromeVersion = CLng(Split(sVersion, &quot;.&quot;, 2)(0))
							Exit Sub
						End Select
					End If
				Next
			End If
		Next
		
	End Sub
	
	Private Sub CheckChromeFolders(bFound, sChromePath, lChromeVersion)
		
		&#039; Проверка Chrome в стандартных папках
		
		Dim oFolders, sFolder, sPath, lVersion
		
		bFound = False
		Set oFolders = CreateObject(&quot;Scripting.Dictionary&quot;)
		With CreateObject(&quot;WScript.Shell&quot;)
			oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;localappdata&quot;)) = &quot;&quot;
			oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programfiles&quot;)) = &quot;&quot;
			oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programfiles(x86)&quot;)) = &quot;&quot;
			oFolders.Item(.Environment(&quot;process&quot;).Item(&quot;programw6432&quot;)) = &quot;&quot;
			oFolders.Item(.ExpandEnvironmentStrings(&quot;%programfiles%&quot;)) = &quot;&quot;
			oFolders.Item(.ExpandEnvironmentStrings(&quot;%programfiles(x86)%&quot;)) = &quot;&quot;
		End With
		With CreateObject(&quot;Shell.Application&quot;)
			oFolders.Item(.Namespace(&amp;H26).Self.Path) = &quot;&quot;
			oFolders.Item(.Namespace(&amp;H2A).Self.Path) = &quot;&quot;
		End With
		For Each sFolder In oFolders
			sPath = sFolder &amp; &quot;\Google\Chrome\Application\chrome.exe&quot;
			If CreateObject(&quot;Scripting.FileSystemObject&quot;).FileExists(sPath) Then
				lVersion = GetFileVersion(sPath)
				If lVersion &lt;&gt; &quot;&quot; Then
					bFound = True
					sChromePath = sPath
					lChromeVersion = lVersion
					Exit Sub
				End If
			End If
		Next
		
	End Sub
	
	Private Function GetFileVersion(sPath)
		
		Dim oShell, oFolder, oFile, i, sName, sVersion, sFolderName, sFileName
		
		GetFileVersion = &quot;&quot;
		SplitFullPath sPath, sFolderName, sFileName
		Set oShell = CreateObject(&quot;Shell.Application&quot;)
		Set oFolder = oShell.Namespace(sFolderName)
		Set oFile = oFolder.ParseName(sFileName)
		For i = 0 To 511
			sName = oFolder.GetDetailsOf(oFolder.Items, i)
			If LCase(sName) = &quot;версия файла&quot; Or LCase(sName) = &quot;file version&quot; Then
				sVersion = oFolder.GetDetailsOf(oFile, i)
				Select Case True
					Case sVersion = &quot;&quot;
					Case Not IsNumeric(Split(sVersion, &quot;.&quot;, 2)(0))
					Case Else
						GetFileVersion = CLng(Split(sVersion, &quot;.&quot;, 2)(0))
						Exit Function
				End Select
				Exit Function
			End If
		Next
		
	End Function
	
	Private Sub SplitFullPath(sPath, sFolderName, sFileName)
		
		With CreateObject(&quot;Scripting.FileSystemObject&quot;)
			If Not .FileExists(sPath) Then Exit Sub
			sFolderName = .GetParentFoldername(sPath)
			sFileName = .GetFileName(sPath)
		End With
		
	End Sub
	
End Class</code></pre></div><p>Работает, начиная с версии Chrome 59. Описание прочих возможностей (создание скриншотов страницы и сохранение в формате PDF) и параметров командной строки можно найти по <a href="https://developers.google.com/web/updates/2017/04/headless-chrome">ссылке</a>.<br />Оговорюсь, что код относительно сыроват, для некоторых страниц нужно отлаживать кодировку символов, и, не исключено, добавлять проверку на таймаут.</p></div></div>]]></content>
			<author>
				<name><![CDATA[omegastripes]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29228</uri>
			</author>
			<updated>2018-11-20T01:12:07Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129907#p129907</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Установка и настройка Google Chrome через VBS]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=129905#p129905" />
			<content type="html"><![CDATA[<p>Приветствую всех.</p><p>Помогите пожалуйста нужен скрипт выполняющий функции:</p><p>1. Определение установлен ли браузер Хром на машине или нет, если нет, то скачивание файла с интернета (браузер хром)<br />2. Тихая установка браузера Хром<br />3. Браузер Хром по умолчанию основной<br />4. Установка расширения в браузере Хром (и запуск расширения)<br />5. Отключение всплывающих окон в браузере хром<br />6. Добавление закладки в браузере Хром</p><br /><p> Единственное знаю как скачать файл из интернета и как сделать браузер основным.. больше ничего не знаю.. помогите пожалуйста как будет выглядеть данный скрипт из этих пунктов....</p>]]></content>
			<author>
				<name><![CDATA[cherfull22]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=39640</uri>
			</author>
			<updated>2018-11-19T19:36:19Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=129905#p129905</id>
		</entry>
</feed>
