none
Setting value in Registry for 32-bit ODBC.INI generates an error RRS feed

  • Question

  • Hi

    I'm converting an application previously developed in VB6 to VB.NET.

    The applications small goal is to create a System DSN in 32-bit ODBC-setting on the server on which it is run.

    I get an error (Additional information: Requested registry access is not allowed) trying to Opensubkey for SOFTWARE\WOW6432NODE.

    This is the code:
    Bold line generates the error.

            If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Database", Nothing) Is Nothing Then
                Dim regkey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Wow6432Node", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree, Security.AccessControl.RegistryRights.FullControl)
                Dim subRegkey = regkey.OpenSubKey("ODBC\ODBC.INI", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree, Security.AccessControl.RegistryRights.CreateSubKey)
                subRegkey.CreateSubKey(fDBase)
                subRegkey.Close()
                regkey.Close()
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Database", fDBase.Trim)
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Description", "Periodisk aktuariedatabas")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Driver", "C: \WINDOWS\System32\sqlsrv32.dll")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "LastUser", "Aktuarie")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Regional", "Yes")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Server", "(local)")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\" & fDBase, "Trusted_Connection", "Yes")
                My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ODBC\ODBC.INI\ODBC Data Sources", fDBase, "SQL Server")
    
            End If
    

    I am administrator on the machine and I can create these values using regedit.
    I have tried running debug in both 32-bit and 64-bit mode with same result.
    I have tried with different and no rights parameter in the OpenSubkey command with same result, even though the error occurs on the next line.

    What am I missing here?



    Best Regards Peter Karlström

    Wednesday, May 10, 2017 7:20 AM

Answers

All replies