Hi Dw.

I'm tryign to change a registrykey on my system but I get this error: ArgumentException was unhandled, The specified RegistryKeyPermissionCheck Value is invalid. Parameter name: mode

here is the line that throws this error:

regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Root & Last, True, (Security.AccessControl.RegistryRights.FullControl))

and the rest of the function code is:

Private Function GetRoot(ByVal Adapter As String) As String
        Dim regKey As Microsoft.Win32.RegistryKey
        Dim i As Integer = 0

            Dim Root As String = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\"
            Dim Last As String = DoPadding(i)
            regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Root & Last, True, (Security.AccessControl.RegistryRights.FullControl))

                Dim cAdapter As String = regKey.GetValue("DriverDesc").ToString()
                If cAdapter = Adapter Then
                    Return Root & Last
                End If
                Exit Do
            End Try
            i += 1
End Function

This funtion is called after clicking the update button to update the mac address.

Private Sub bt_update_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_update.Click
        Dim mac_text As String = m1.Text.ToUpper + ":" & m2.Text.ToUpper + ":" & m3.Text.ToUpper + ".:" & m4.Text.ToUpper + ":" & m5.Text.ToUpper + ":" & m6.Text.ToUpper
        If IsOkay() = False Then
            Exit Sub
        End If
        Dim regKey As Microsoft.Win32.RegistryKey
        Dim Addr As String = GetRoot(combo_network.SelectedItem.ToString())
        regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Addr, True)

        regKey.SetValue("NetworkAddress", mac_text.ToString.Replace(":", ""))
    End Sub

I've tried changing all the available access/modificication permissions that are available within that line but still it just throw this error message.

Thank you

Recommended Answers

All 2 Replies


I tried out your code and was able to read a value from that section of the registry, but not DriverDesc as I only have ClassDesc there. The only argument I needed to change was the writeable property which I set to False as it seems that you are only attempting to read the value:

regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(Root & Last, False, (Security.AccessControl.RegistryRights.FullControl))


Thanks. Sorry to take so long but I was busy with other projects. Well now my problem is that even if I've set the values but they are not being saved to the registry.

I have another working program I've downloaded which does change my MAC address but when I'm using mine, the above code (btn_update) the keys/values are not being saved to the registry even after I've disabled and enabled the adapter but still my this code doesn't update the registry.

Is there any thing I'm missing out here or perhaps is there any better way to write to the registry?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.