• 环境变量.JAVA_HOME


    1、资料:(我的文章)

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

    2、

      2.1、界面

      2.2、代码

    unit formMain;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Registry, IniFiles;
    
    type
      TfrmMain = class(TForm)
        btnRegeditWrite: TButton;
        Memo1: TMemo;
        btnRegeditRead: TButton;
        edtJavaHome: TEdit;
        procedure btnRegeditWriteClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure btnRegeditReadClick(Sender: TObject);
      public
        function ReadString( _dwRootKey :DWORD; const _strPath, _strKey :string; var _strOut : string):Integer;
        function WriteString(_dwRootKey :DWORD; const _strPath, _strKey, _strValue :string):Integer;
      public
        function ReadIni():integer;
      end;
    
    var
      frmMain: TfrmMain;
    
    implementation
    
    {$R *.dfm}
    
    function TfrmMain.ReadString(_dwRootKey :DWORD; const _strPath, _strKey: string; var _strOut: string): Integer;
    var reg :TRegistry;
    begin
      Result := 0;
      reg := TRegistry.Create;
      try
        reg.RootKey := _dwRootKey;//HKEY_LOCAL_MACHINE; //'SYSTEMCurrentControlSetControlSession ManagerEnvironment'
        if not reg.OpenKey( _strPath, false ) then
        begin
          Result := -1;
          Exit;
        end;
    
        _strOut := reg.ReadString(_strKey);
      finally
        reg.CloseKey;
        reg.Destroy;
      end;
    end;
    
    function TfrmMain.WriteString(_dwRootKey: DWORD; const _strPath, _strKey, _strValue: string): Integer;
    var reg :TRegistry;
    begin
      reg := TRegistry.Create;
      try
        reg.RootKey := _dwRootKey;//HKEY_LOCAL_MACHINE; //'SYSTEMCurrentControlSetControlSession ManagerEnvironment'
        if not reg.OpenKey( _strPath, false ) then
        begin
          Result := -1;
          Exit;
        end;
    
        reg.WriteString( _strKey, _strValue );
      finally
        reg.CloseKey;
        reg.Destroy;
      end;
    end;
    
    
    procedure TfrmMain.FormCreate(Sender: TObject);
    begin
      ReadIni;
      btnRegeditReadClick(nil);
    end;
    
    procedure TfrmMain.btnRegeditWriteClick(Sender: TObject);
    var strValue :string;
    begin
      Memo1.Lines.Add('');
    // HKEY_LOCAL_MACHINESYSTEMControlSet001Session ManagerEnvironmentpath
    // HKEY_CURRENT_USER Environment
    // HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment (官方)
    
      //strValue := 'C:Program FilesJavajdk1.8.0_152;AAA';
      //strValue := 'C:Program FilesJavajdk1.8.0_152';
      strValue := trim(edtJavaHome.Text);
      if (strValue = '') then
      begin
        Memo1.Lines.Add('新的 JAVA_HOME 的值为空 .');
        Exit;
      end;
      
      if 0>WriteString(HKEY_LOCAL_MACHINE,
        'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'JAVA_HOME', strValue) then
      begin
        Memo1.Lines.Add('注册表写入失败 .');
        Exit;
      end;
      Memo1.Lines.Add('注册表写入成功 .');
    end;
    
    procedure TfrmMain.btnRegeditReadClick(Sender: TObject);
    var strValue :string;
    begin
      Memo1.Lines.Add('');
    
      if (0 > ReadString(HKEY_LOCAL_MACHINE,
        'SYSTEMCurrentControlSetControlSession ManagerEnvironment', 'JAVA_HOME', strValue)) then
      begin
        Memo1.Lines.Add('读取 注册表 出错');
        Exit;
      end;
      Memo1.Lines.Add('HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironmentJAVA_HOME');
      Memo1.Lines.Add('   '+strValue);
    end;
    
    function TfrmMain.ReadIni(): integer;
    var ini :Tinifile;
        strX86, strX64 :string;
        strFileName :string;
    begin
      strFileName := ExtractFilePath(Paramstr(0)) + '_EnvironmentVariable.ini';
      ini := Tinifile.Create(strFileName);
      try
        strX86 := 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);
      finally
        ini.Free;
      end;
    end;
    
    end.

      2.3、ini文件(_EnvironmentVariable.ini)

    3、

    4、

    5、

  • 相关阅读:
    札记:计算机网络篇:物理层
    vs2012 它已停止工作
    php laravel 帧 该文件上传
    2016第一周日
    2015年第1周六
    2016第1周五优化自己
    2016值得关注的语言平台、JS框架
    JS模块化规范CommonJS,AMD,CMD
    2016第1周二
    ReactJS入门教程
  • 原文地址:https://www.cnblogs.com/CodeSkill/p/8341464.html
Copyright © 2020-2023  润新知