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;
}
}