配置JAVA环境变量实际上是要修改系统的环境变量,MSDN中有许多修改环境变量的函数。调用比如SetEnvironmentVariable()这样的环境变量设置函数。都是无法修改系统的环境变量的,只能改变本进程的环境变量。要修改系统环境变量只能通过修改注册表,并发送同步消息给相关处理程序。
下面是MSDN原文:
Environment Variables
Calling SetEnvironmentVariable has no effect on the system environment variables. To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environmentregistry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.
------------------------------------------------------------------------------------------------------------------------------------------------------------
所以想实现这一功能只能通过注册表修改实现