在Win7中没有管理员权限的情况下在注册表中读取Dsn

时间:2017-03-15 10:53:46

标签: c# vb.net

在win7中,我需要在注册表中读取一些dns,但没有管理员权限。

如何在Vb.Net或c#中执行此操作?

dsn位于HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBC.INI和

HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ ODBC \ ODBC.INI

提前谢谢

P.S。我使用此代码,但无法正常工作

        Dim registryKey As RegistryKey
    Dim registrySubKey As RegistryKey

    Try

        registryKey = Registry.LocalMachine
        registrySubKey = Registry.LocalMachine.OpenSubKey(sString, True)

        SourceRegInfo.Add(New Model_DatiRegestry() With _
        { _
            .DataBase = registrySubKey.GetValue("DataBase"), _
            .Description = registrySubKey.GetValue("Description"), _
            .Server = registrySubKey.GetValue("Server")
        })

        registrySubKey.Close()
        registryKey.Close()

        GetValueDns = True

    Catch ex As Exception
        GetValueDns = False
        MessageBox.Show(Err.Description, "GetValueDns !!", MessageBoxButton.OK, MessageBoxImage.Information)
    End Try

解决.. !!!这段代码还可以......

    Dim PathFind As String = "HKEY_LOCAL_MACHINE\" ' bla bla bla


        Dim sDataBase = My.Computer.Registry.GetValue(PathFind + sString, "DataBase", Nothing)
        Dim sDescription = My.Computer.Registry.GetValue(PathFind + sString, "Description", Nothing)
        Dim sServer = My.Computer.Registry.GetValue(PathFind + sString, "Server", Nothing)
        SourceRegInfo.Add(New Model_DatiRegestry() With _
        { _
            .DataBase = sDataBase, _
            .Description = sDescription, _
            .Server = sServer
        })

        GetValueDns = True

0 个答案:

没有答案