Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone :)

I'm Trying to write a value into the registry with no success so far

im trying to write the value True to REG_SZ in a new registery hive
heres my code so far:

VB
My.Computer.Registry.CurrentUser.CreateSubKey("Software\Real_Estate_Program")
My.Computer.Registry.CurrentUser.SetValue("Software\Real_Estate_Program", "REG_SZ", RegistryValueKind.String)
My.Computer.Registry.CurrentUser.SetValue("c", "True")
Console.WriteLine(My.Computer.Registry.CurrentUser.GetValue("Software\Real_Estate_Program\REG_SZ"))
Console.ReadLine()


I'll be thankfull if some 1 will point where's my mistake.

Thenk you in advance, tsahi.
Posted

 
Share this answer
 
Comments
tsahi-al 18-Oct-11 9:21am    
Worked like a Charm, Ty :D
joe_j 19-Oct-11 10:11am    
np..enjoy
REG_SZ is a string value in the registry.

Use
VB
My.Computer.Registry.CurrentUser.SetValue("Software\Real_Estate_Program", "c", "True")

or
VB
My.Computer.Registry.CurrentUser.SetValue("Software\Real_Estate_Program", "c", "True", RegistryValueKind.String)

In the first call the SetValue[^] determines that the value needs to be stored as a REG_SZ, because you are passing the value as a string.
The RegistryValueKind.String[^] enum in the second call tells the SetValue[^] function you want to store the value as a REG_SZ.

To retrieve this value from the registry use
VB
My.Computer.Registry.CurrentUser.GetValue("Software\Real_Estate_Program\", "c", "default")

The last parameter in the GetValue call is returned by the function when the key you are retrieving does not exist.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900