Java uses JRegistry-1.8.1 to read and set windows registries, jregistry

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.