Reputation: 6557
I want to read the port number for remote desktops, but it doesn't work.
MSDN states that it is at
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber
which is a key that exists in my registry on Windows 8.
private void Form1_Load(object sender, EventArgs e)
{
txtPort.Text = (string) Registry.GetValue(@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp", "PortNumber", "");
}
The string returned is null.
Correct answer:
private void Form1_Load(object sender, EventArgs e)
{
txtPort.Text = Registry.GetValue(@"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\", "PortNumber", -1).ToString();
}
Upvotes: 1
Views: 278
Reputation: 217371
There's a space in "Terminal Server":
@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp"
↑
Upvotes: 7