在一个监控相关的Java项目中,需要读取windows系统的注册表,搜索到使用 JRegistery 可以解决。代码如下:
/**
* @author digdeep@126.com
*/
public class RegstryUtil
{
//"HKEY_LOCAL_MACHINE"
public static final RegistryKey LOCALMACHINE = RegistryKey.getRootKeyForIndex(RegistryKey.HKEY_LOCAL_MACHINE_INDEX);
// "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\"
public static final RegistryKey rdpKey = new RegistryKey(LOCALMACHINE,
"\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\\");
/**
* 获得 windows server 中的 terminal server 的端口
* 也就是远程桌面服务的端口
* @return
*/
public static long getTerminalServerPort() {
long port = -1;
if(rdpKey.hasValues()) {
RegistryValue portNumber =