Java access registry profiling

Source: Internet
Author: User

 

Java accesses the Registry Information 'ice _ jniregistry. dll 'and 'registry. jar'

First, download ice_jniregistry.dll and registry. jar files. After downloading the files, put ice_jniregistry.dll in the bin directory of Tomcat and set registry. put jar in the lib directory of the project. (However, I have seen on the Internet that I want to put all the two files under lib and bin. I cannot explain it)

To read the installation path of a service, go to the following directory in the registry:

HKEY_LOCAL_MACHINE> Software> Microsoft> WINDOWS-CURRENTVERSION> app paths

After finding the service you want to find, for example, 360safe.exe, its path describes its installation path. My previous requirement is to know a service name to obtain its installation path. I have not yet understood other requirements. In Java, only two lines of simple code can be called. For example, to read the 360safe installation path, the Code is as follows:

Registrykey software = registry. HKEY_LOCAL_MACHINE. opensubkey ("software ");
Registrykey subkey = software. opensubkey ("Microsoft "). opensubkey ("Windows "). opensubkey ("CurrentVersion "). opensubkey ("app paths "). opensubkey ("360safe.exe ");
Path = subkey. getstringvalue ("")

However, in actual application, the path is Chinese. If the path has Chinese characters, we need to first encode the path. Otherwise, Chinese characters may be garbled.

You can use the following method to complete transcoding:

Private Static string encodeval (string Val)
{
Try
{
Byte [] Buf = Val. getbytes ("Unicode ");
Bytetocharconverter converter = bytetocharconverter. getconverter ("ISO-8859-1 ");
Char C [] = converter. convertall (BUF );
Int I, J;
Char [] CH = new char [C. Length/2 + 1];
For (I = 2, j = 0; I <C. length; I ++) {// extract useful characters to the new array
If (I % 2 = 0)
{
Ch [J ++] = C [I];
}
}
Byte [] tmpbuf = new byte [J];
For (I = 0; I <j; I ++)
{
Tmpbuf [I] = (byte) CH [I];
}
Converter = bytetocharconverter. getconverter ("gb2312 ");
Char GBC [] = converter. convertall (tmpbuf );

Return new string (GBC );
}
Catch (exception E)
{
System. Out. println (E. getmessage ());
Return NULL;
}
}

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.