public static void Change(int port)
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Terminal Server\Wds\rdpwd\Tds\tcp", true);
if (runKey != null)
{
runKey.SetValue("PortNumber", port);
runKey.Close();
}
runKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\ControlSet001\Control\Terminal Server\WinStations\RDP-Tcp", true);//win7
if (runKey != null)
{
runKey.SetValue("PortNumber", port);
runKey.Close();
}
runKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentContro1Set\Control\Tenninal Server\WinStations\RDP\Tcp", true);//win2003
if (runKey != null)
{
runKey.SetValue("PortNumber", port);
runKey.Close();
}
MessageBox.Show("修改成功,重启电脑后生效。");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}