Page 1 of 1

Check Registry for Webrowser Key

PostPosted: Sun Jun 16, 2013 11:43 am
by paeon09
Hi Everyone,

I was struggling with this, even thought I had ie10 installed my browser would not work on certain sites that disliked ie7.

Worked out how to write the key to the registry with help from this board, many thanks, but I still need to check if
the key was already there, and reading the key throws an error.

Did some searching and found a wonderful script(see below) that with some very small mods works fantastic, if there
are any flaws in this I would be grateful to know as I am not a VB programmer, and hope this helps someone else.

Code: Select all
'-------------------------------------------------------------------------------------------
'Script Name : ReadRegistry.vbs
'Author      : Matthew Beattie
'Created     : 09/01/09
'Description : This script demonstrates the use of the wshShell RegRead Method
'            : to read and convert a binary value.
'-------------------------------------------------------------------------------------------
'Initialization  Section
'-------------------------------------------------------------------------------------------
Option Explicit
Dim objFSO, wshShell, scriptBaseName
On Error Resume Next
   Set objFSO     = CreateObject("Scripting.FileSystemObject")
   Set wshShell   = CreateObject("Wscript.Shell")
   scriptBaseName = objFSO.GetBaseName(Wscript.ScriptFullName)
   If Err.Number <> 0 Then
      Wscript.Quit
   End If
On Error Goto 0
'-------------------------------------------------------------------------------------------
'Main Processing Section
'-------------------------------------------------------------------------------------------
On Error Resume Next
   ProcessScript
   If Err.Number <> 0 Then
      Wscript.Quit
   End If
On Error Goto 0
'-------------------------------------------------------------------------------------------
'Functions Processing Section
'-------------------------------------------------------------------------------------------
Function ProcessScript
   Dim regValue, regKey
   regKey   = "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\[%1]"
   regValue = ReadRegistry(regKey)
   If regValue = "" Then
      'MsgBox regKey & " does not exist.", vbCritical, scriptBaseName
      ' Create a new key:
       wshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\", ""

      ' Create a new DWORD value:
      wshShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\[%1]", 00000000, "REG_DWORD"
         publication.nbSetVar "[%2]", "Its Not Here"
      Exit Function
   End If
      'MsgBox regKey & " = " & regValue, vbInformation, scriptBaseName
        publication.nbSetVar "[%2]", "Its Here"
End Function
'-------------------------------------------------------------------------------------------
'Name       : ReadRegistry -> Read the value of a registry key or value.
'Parameters : key          -> Name of the key (ending in "\") or value to read.
'Return     : Value of key or value read from the local registry (blank is not found).
'             Binary values are converted to a string of hexadecimal digits (two per byte).
'-------------------------------------------------------------------------------------------
Function ReadRegistry(ByVal key)
   Dim result
   If StrComp(Left (key, 4), "HKU\", vbTextCompare) = 0 Then
      Key = "HKEY_USERS" & Mid (key, 4)
   End If
   On Error Resume Next
      result = WshShell.RegRead(key)
      If Err.Number = 0 Then
         If VarType (result) >= vbArray Then
            Dim strResult, element
            strResult = ""
            For Each element In result
               strResult = strResult & Right ("0" & Hex (element), 2)
            Next
            ReadRegistry = strResult
         Else
            ReadRegistry = result
         End If
      Else
         ReadRegistry = ""
      End If
   On Error goto 0
End Function


Tony

Re: Check Registry for Webrowser Key

PostPosted: Mon Jun 17, 2013 10:28 am
by Neosoft Support
Hi Tony,

Thanks for sharing this with us.