String Registry Write

Anyone know why VB.net isnt accepting a standard String Registry Key? I know in VS2005 the way some of the registry mechanics work have change a bit.

Call WriteKey("LicenseKey", "123456789"

PublicFunction WriteKey(ByVal strKey,ByVal strValue)

My.Computer.Registry.LocalMachine.SetValue("HKEY_LOCAL_MACHINE\Software\MySoftware\MyApp\", strKey, strValue)

WriteKey =True

EndFunction

[1031 byte] By [Sigfuss] at [2007-12-24]
# 1

Hi

This will Work fine

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Call WriteKey("LicenseKey", "123456789")

End Sub

Public Function WriteKey(ByVal strKey, ByVal strValue)

Dim StartupPath As String = "Software\MySoftware\MyApp\"

Dim MyKey As RegistryKey = Registry.LocalMachine.OpenSubKey(StartupPath, True)

Try

MyKey.SetValue(strKey, strValue)

Return True

Catch ex As Exception

Return False

End Try

End Function

SamerSelo at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

You shouldn't have to include the HKEY_LOCAL_MACHINE part. Try the following

My.Computer.Registry.LocalMachine.SetValue("Software\MySoftware\MyApp", strKey, strValue)

JaredParsonsMSFT at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

What namespace does RegistryKey appear under?

This gives me an error:

Dim MyKey As RegistryKey = Registry.LocalMachine.OpenSubKey(StartupPath, True)


Noctufaber at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic Language...