Read and write to the Registry with VB
Posted on 2014-12-11
I am trying to write a small application using Visual Basic 2013 that will read the port number for Remote Desktop from the registry then pass that information to a text box. Then if I need to change the port number I can enter that port number in the text box and pass it back to the registry.
This bit of code works to get the number and is pretty straight forward:
Dim readValue = My.Computer.Registry.GetValue(
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", "PortNumber", Nothing)
PortTxtBx.Text = readValue
My problem is trying to write the value back to the registry.
I know that I want build a test this application in the normal way because it has to be run elevated to administrator so testing is a little unwieldy in so far as I have to build the app then run it.
I need to keep this as simple as possible because only have to use it about 40 times.
If someone has another idea such as script I am all ears.