ZC: 我的示例代码(Delphi):http://www.cnblogs.com/CodeSkill/p/8341464.html

1、资料:

  如何用代码设置环境变量?-CSDN论坛.html(http://bbs.csdn.net/topics/50445308

  如何修改Windows系统环境变量 _ 蓝讯.html(http://www.lxway.com/261806661.htm

  How to propagate environment variables to the system.html(https://support.microsoft.com/en-us/help/104011/how-to-propagate-environment-variables-to-the-system

  1.1、SetEnvironmentVariable --> 无法影响到 系统环境变量(∴ 用它修改的话,在 "???-->系统属性-->环境变量" 的窗口里面是看不到对应的变化的)

  1.2、直接修改 注册表 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment 里面的键值(要想所有窗口都立即知道环境变量改变了的话,就需要广播[下面资料里面有])

    ZC: 在 CSDN的帖子里面 提到 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Session Manager\Environment\path,自己弄了一下,这里改了的话 "环境变量"里面的值也会变。测试了一下:"...\CurrentControlSet\...\Environment"和"...\ControlSet001\...\Environment" 中的值,不管修改哪边的键值,另一边是会跟着变的,但是 保守起见 还是用 MSDN里面官方说的地方吧...

  1.3、CSDN的帖子里 还提到一个函数:ExpandEnvironmentStrings,未做测试 也未查看相关资料...

2、MSDN中的资料:(https://support.microsoft.com/en-us/help/104011/how-to-propagate-environment-variables-to-the-system

How to propagate environment variables to the system


Summary


You can modify user environment variables by editing the following Registry key:

   HKEY_CURRENT_USER \ 
Environment

You can modify system environment variables by editing the following Registry key:

   HKEY_LOCAL_MACHINE \ 
SYSTEM \
CurrentControlSet \
Control \
Session Manager \
Environment

Note that any environment variable that needs to be expanded (for example, when you use %SYSTEM%) must be stored in the registry as a REG_EXPAND_SZ registry value. Any values of type REG_SZ will not be expanded when read from the registry.

Note that RegEdit.exe does not have a way to add REG_EXPAND_SZ. Use RegEdt32.exe when editing these values manually.

However, note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on.

To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Windows Explorer, Program Manager, Task Manager, Control Panel, and so forth) can perform an update.

More Information


For example, on Windows NT-based systems, the following code fragment should propagate the changes to the environment variables used in the Command Prompt:

   SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
(LPARAM) "Environment", SMTO_ABORTIFHUNG,
5000, &dwReturnValue);

None of the applications that ship with Windows 95 and Windows 98, including Windows Explorer and Program Manager, respond to this message. Thus, while this article can technically be implemented on Windows 95 and Windows 98, there is no effect except to notify third-party applications. The only method of changing global environment variables on Windows 95 is to modify the autoexec.bat file and reboot.

 

Last Updated: Jan 8, 2017
 
 

3、

4、

5、

Windows.环境变量(设置)的更多相关文章

  1. Windows环境变量设置无效解决办法——DOS窗口设置环境变量

    公司配置的电脑是Win7,使用的账户并不是管理员账户,我在计算机->属性中设置环境变量无效. 后来在DOS窗口中设置环境变量成功. 1. set [环境变量名称]=[所有环境变量值]:set P ...

  2. MySQL Windows环境变量设置

    问题:MySQL无法全局使用 1.查找MySQL路径 2.添加环境变量 3.验证功能

  3. Windows 7下java SDK下载、安装及环境变量设置

    第一步:下载Java JDK   1 登录官网站下载正版JDK   2 点击"SDK Download"进入Java JDK下载页面 注明: Java JDK和Java JRE区别 ...

  4. (转)windows 下 Java 及 Python 环境变量设置

    转自:http://www.cnblogs.com/zhj5chengfeng/archive/2013/01/01/2841253.html http://www.cnblogs.com/qiyes ...

  5. 通过修改注册表设置windows环境变量

    开发环境搭建每次都要设置很多环境变量, 一般是通过  [菜单]->[计算机]->[属性]->[高级设置]->[环境变量]进行设置,重装系统后,每次都要设置很多环境变量,很麻烦. ...

  6. 【转】Windows 平台下 Go 语言的安装和环境变量设置

    1. Go 语言 SDK 安装包下载和安装 最新稳定版 1.5.3 安装包 go1.5.3.windows-amd64.msi下载地址 https://golang.org/dl/,大小约 69 MB ...

  7. windows和linux-JDK环境变量设置

    Windows环境变量添加或修改以下内容: JAVA_HOME=C:\Program Files\Java\jdk1..0_43 --注意修改路径 CLASSPATH=.;%JAVA_HOME%\li ...

  8. Windows 平台下 Go 语言的安装和环境变量设置

    1. Go 语言 SDK 安装包下载和安装 最新稳定版 1.5.3 安装包 go1.5.3.windows-amd64.msi下载地址 https://golang.org/dl/,大小约 69 MB ...

  9. GO语言学习(一)Windows 平台下 Go 语言的安装和环境变量设置

    1. Go 语言 SDK 安装包下载和安装 GO语言安装包下载地址:https://www.golangtc.com/download 下载 go1.9.2.windows-amd64 2. Go 语 ...

随机推荐

  1. 怎样从外网访问内网WebLogic?

    本地安装了一个WebLogic,只能在局域网内访问,怎样从外网也能访问到本地的WebLogic呢?本文将介绍具体的实现步骤. 准备工作 安装并启动WebLogic 默认安装的WebLogic端口是70 ...

  2. Errors occurred during the build. Errors running builder 'Validation' on pro

    选择项目-->右键-->Properties-->Builders   右面有四个选项,把Validation前面勾去掉

  3. jbpm 6 vs activities 5评估(持续更新、亲测实际项目评估)

    最近我们有个使用了jbpm 6.2(6.2是一个较大的里程碑)的批处理模块,因为大BOSS一直觉得太重了,希望有更加轻量级的解决方案,因为我们基本上没有真正意义上流程的概念,只有静态的流程图,因为一直 ...

  4. 【题解】 Luogu CF375D Tree and Queries

    原题传送门 这道题要用树链剖分,我博客里有对树链剖分的详细介绍 我博客中对莫队的详细介绍 莫队好题 我一上来想写线段树,随后觉得不好写并弃坑 我们可以看见没有修改操作,钦定莫队 但这是在树上,所以不能 ...

  5. 【题解】Luogu P4363 [九省联考2018]一双木棋chess

    原题传送门 这道题珂以轮廓线dp解决 经过推导,我们珂以发现下一行的棋子比上一行的棋子少(或等于),而且每一行中的棋子都是从左向右依次排列(从头开始,中间没有空隙) 所以每下完一步棋,棋盘的一部分是有 ...

  6. 监控mysql状态脚本

    监控mysql状态, 发现宕后, 自动重启, 每秒检查一次. check.sh #!/bin/bash while [ true ]; do /bin/sleep 1 sh mysql_status. ...

  7. python简说(十五)MD5加密

    def my_md5(s): news = str(s).encode() m = hashlib.md5(news) return m.hexdigest()

  8. centos6.5新增加硬盘挂载并实现开机自动挂载

    在内网主机新增一个2T硬盘,先关机断电再连接硬盘数据线和电源线! 查看当前磁盘设备信息: [root@tb ~]# fdisk -l WARNING: GPT (GUID Partition Tabl ...

  9. shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢?

    shell中的变量a=100, 什么时候作整数使用, 什么时候作字符串使用呢? 这确实是一个困扰很久的一个问题? how it can be an issue? 事实上, 在shell中, 你可以认为 ...

  10. shell编程中的 三种结构: 条件if/选择结构case/循环for/while/until等结构 和 函数的用法

    shell 函数的使用 (md中, 列表本身是有格式的, 他要产生缩进, 其次,列表项和列表项之间, 可以留有一个空行, 是合法的, 允许的) shell函数,就是 就相当于一个命令来看待和处理的, ...