Java uses JRegistry-1.8.1 to read and set windows registries, jregistry
In a monitoring-related Java project, you need to read the windows registry and search to use JRegistery. The Code is as follows:
/*** @ 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 \\"); /*** obtain the terminal server port * in windows server, that is, the remote desktop service port * @ return */public static long getTerminalServerPort () {long port =-1; if (rdpKey. hasValues () {RegistryValue portNumber = rdpKey. getValue ("PortNumber"); System. out. println (portNumber. toString (); // Name: PortNumber Type: REG_DWORD Value: 3389 String value = portNumber. toString (); port = Long. valueOf (value. substring (value. lastIndexOf (":") + 2); System. out. println ("port:" + port);} return port;} public static void main (String [] args) {getTerminalServerPort ();}}
What is implemented is to read the port used by the terminal service of the Remote Desktop service on the server. The default value is generally 3389, but it can be modified. Therefore, you need to read the value from the registry.
Reference: http://blog.sina.com.cn/s/blog_9707fac30101hdvy.html
You need to put reg. dll or reg_x64.dll in the bin directory of java JDK during runtime. Add a jregistry-1.8.1.jar file to the classpath.