Environment variables. Java_home

Source: Internet
Author: User

1. Information: (my article)

Http://www.cnblogs.com/cppskill/p/8341263.html

2.

2.1. Interface

2.2. Code

UnitFormMain;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Registry, inifiles;
    typeTfrmmain=class(tform) Btnregeditwrite:tbutton;    Memo1:tmemo;    Btnregeditread:tbutton;    Edtjavahome:tedit; procedureBtnregeditwriteclick (Sender:tobject); procedureformcreate (Sender:tobject); procedureBtnregeditreadclick (Sender:tobject);  Public    functionReadString (_dwrootkey:D Word;Const_strpath, _strkey:string;var_strout:string): Integer; functionWriteString (_dwrootkey:D Word;Const_strpath, _strkey, _strvalue:string): Integer;  Public    functionReadini (): integer; End;varFrmmain:tfrmmain;Implementation{$R *.DFM}functionTfrmmain.readstring (_dwrootkey:D Word;Const_strpath, _strkey:string;var_strout:string): Integer;varReg:tregistry;beginResult:=0; REG:= Tregistry.Create; TryReg. Rootkey:= _dwrootkey;//HKEY_LOCAL_MACHINE;//' SYSTEM\CurrentControlSet\Control\Session manager\environment '    if  notReg. Openkey (_strpath, False) Then    beginResult:= -1;    Exit; End; _strout:=Reg.  ReadString (_strkey); finallyReg.    Closekey; Reg.Destroy; End;End;functionTfrmmain.writestring (_dwrootkey:dword;Const_strpath, _strkey, _strvalue:string): Integer;varReg:tregistry;beginReg:= Tregistry.Create; TryReg. Rootkey:= _dwrootkey;//HKEY_LOCAL_MACHINE;//' SYSTEM\CurrentControlSet\Control\Session manager\environment '    if  notReg. Openkey (_strpath, False) Then    beginResult:= -1;    Exit; End; Reg.  WriteString (_strkey, _strvalue); finallyReg.    Closekey; Reg.Destroy; End;End;proceduretfrmmain.formcreate (sender:tobject);beginReadini; Btnregeditreadclick (Nil);End;procedureTfrmmain.btnregeditwriteclick (sender:tobject);varstrvalue:string;beginMemo1.Lines.Add ("');//hkey_local_machine\system\controlset001\session Manager\environment\path//HKEY_CURRENT_USER \environment//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (official)  //strvalue: = ' C:\Program files\java\jdk1.8.0_152; AAA ';  //strvalue: = ' C:\Program files\java\jdk1.8.0_152 ';strvalue: =trim (edtjavahome.text); if(strvalue ="') Then  beginMemo1.Lines.Add ('the value of the new Java_home is empty.');  Exit; End; if 0>writestring (HKEY_LOCAL_MACHINE,'system\currentcontrolset\control\session Manager\Environment','Java_home', strvalue) Then  beginMemo1.Lines.Add ('registry write failed.');  Exit; End; MEMO1.LINES.ADD ('Registry write succeeded.');End;procedureTfrmmain.btnregeditreadclick (sender:tobject);varstrvalue:string;beginMemo1.Lines.Add ("'); if(0>ReadString (HKEY_LOCAL_MACHINE,'system\currentcontrolset\control\session Manager\Environment','Java_home', strvalue)) Then  beginMemo1.Lines.Add ('Error reading Registry');  Exit; End; MEMO1.LINES.ADD ('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\environment\java_home'); MEMO1.LINES.ADD ('   '+strvalue);End;functionTfrmmain.readini (): integer;varIni:tinifile; strX86, strX64:string; strFileName:string;beginstrFileName:= Extractfilepath (Paramstr (0)) +'_environmentvariable.ini'; INI:= Tinifile.Create(strFileName); TrystrX86:= ini. ReadString ('Java_home','win7x86',"'); STRX64:= ini. ReadString ('Java_home','win7x64',"'); MEMO1.LINES.ADD ('Java_home (win7x86):'+strX86); MEMO1.LINES.ADD ('Java_home (win7x64):'+strX64); finallyINI.  Free; End;End;End.

2.3. ini file (_environmentvariable.ini)

3.

4.

5.

Environment variables. Java_home

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.