VB.Net 註冊表 讀寫

'寫入註冊表 WebBrowser1設定內核
Private Function SetRegistry(ByVal strKey As String, ByVal strName As String, ByVal strValue As String) As Boolean
        Try
            Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
            Key_LocalMachine = My.Computer.Registry.CurrentUser 'get the key path of HKEY_LOCAL_USER    
            Dim Key_Created As Microsoft.Win32.RegistryKey
            Key_Created = Key_LocalMachine.OpenSubKey(strKey, True) 'set the true for can write
            If Key_Created Is Nothing Then
                Key_Created = Key_LocalMachine.CreateSubKey(strKey) 'careat the key 
            End If
            Key_Created.SetValue(strName, strValue, Microsoft.Win32.RegistryValueKind.DWord) 'set the values of the key
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

'判斷註冊表
Private Function RegistryExist(ByVal strKey As String, ByVal strName As String) As Boolean
        Try
            Dim Key_LocalMachine As Microsoft.Win32.RegistryKey
            Key_LocalMachine = My.Computer.Registry.CurrentUser 'get the key path of HKEY_LOCAL_USER     
            Dim Key_Exist As Microsoft.Win32.RegistryKey
            Key_Exist = Key_LocalMachine.OpenSubKey(strKey, True) 'set the true for can write
            If Key_Exist Is Nothing Then
                Return False
            End If
            If Key_Exist.GetValue(strName) Is Nothing Then
                Return False
            End If
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

 

 If RegistryExist("Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", My.Application.Info.AssemblyName & ".exe") = False Then '判斷如果註冊表 鍵值不存在
            SetRegistry("Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", My.Application.Info.AssemblyName & ".exe", "11001") '寫入註冊表
        End If

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章