Click here to Skip to main content
15,893,668 members

Create registry key in VB.NET

Vert12 asked:

Open original thread
Can we write to registry key
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION
with out admin priviliges in vb.net from the application

What I have tried:

Dim app = Path.GetFileName(Application.ExecutablePath)
        Dim Regkey As RegistryKey = Nothing
        Dim lobjCurrentUserSPClientRegistryKey As Microsoft.Win32.RegistryKey
        If Environment.Is64BitProcess Then
            Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION")  'For 32 bit machine
        Else
            Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION")
        End If

        Dim lobjCurrentUserRegistry As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine

        If Environment.Is64BitProcess Then
            lobjCurrentUserSPClientRegistryKey = lobjCurrentUserRegistry.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree)
            'Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", True)  'For 32 bit machine
        Else
            lobjCurrentUserSPClientRegistryKey = Regkey 'Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", True)
        End If


        If (lobjCurrentUserSPClientRegistryKey IsNot Nothing) Then
            Dim lobjRegistryPreToolDocSubKey As Microsoft.Win32.RegistryKey = lobjCurrentUserSPClientRegistryKey.OpenSubKey(app, RegistryKeyPermissionCheck.ReadWriteSubTree)

            If (lobjRegistryPreToolDocSubKey Is Nothing) Then
                '
                ' Create this "Previous Tool Documents" sub key.
                '
                lobjRegistryPreToolDocSubKey = lobjCurrentUserSPClientRegistryKey.CreateSubKey(app, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree)
            End If


            lobjRegistryPreToolDocSubKey.Dispose()
            lobjCurrentUserSPClientRegistryKey.Dispose()
            lobjCurrentUserRegistry.Dispose()

            SetRegistryValue("Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", app, "11001")
        End If
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900