SETX.exe (Resource Kit, Windows 7)

Set environment variables permanently, SETX can be used to set Environment Variables for the machine (HKLM) or currently logged on user (HKCU):

Syntax

   SETX [/s Computer [Credentials]] Variable Value [/m]

   SETX [/s Computer [Credentials]] [Variable] /k Path [/m]

   SETX [/s Computer [Credentials]] /f FileName {[Variable] {/a X,Y | /r X,Y "String"}
[/m] | /x} [/d Delimiters] Key: /s Computer
The name or IP address of a remote computer.
Do not use backslashes. (default = the local computer) Credentials
The username and password used to connect to Computer:
/u [Domain\]UserName [/p [Password]]] /u [Domain\]UserName
Run the script with the credentials of the specified user account.
The default value is the system permissions. /p [Password]
The password of the user account that is specified in the /u parameter. Variable
The name of the environment variable that you want to set. Value
The value to which you want to set the environment variable. /k Path
Specifies that the variable is set based on information from a registry key.
The path uses the following syntax: \HIVE\KEY\...\Value For example, you might specify the following path:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName /f FileName
The file that you want to use. /a X,Y
Specifies absolute coordinates and offset as search parameters. /r X,Y "String"
Specifies relative coordinates and offset from String as search parameters. /m
Set the variable in the system environment HKLM.
(The default is the local environment HKCU) /x
Display file coordinates, ignoring the /a, /r, and /d command-line options. /d Delimiters
Specifies delimiters such as "," or "\" to be used in addition to the four
built-in delimiters — SPACE, TAB, ENTER, and LINEFEED.
Valid delimiters include any ASCII character.
The maximum number of delimiters is 15, including built-in delimiters.

Under Windows XP all switches are prefixed with - instead of /.

Early versions of SETX (XP) do not support the options /k,/u,/p or /s

SETX may be used to set environment variables from one of three sources (modes): Command Line Mode, Registry Mode, or File Mode.

Command Line Mode

Environment variables are stored in the registry:

User Variables: HKEY_CURRENT_USER\Environment System Variables: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Because SETX writes variables to the master environment in the registry, edits will only take effect when a new command window is opened - they do not affect the current CMD or PowerShell session.

Machine variables are stored on the machine and will not follow a users roaming profile. To set a machine variable (/m) requires Administrator rights.

User variables are stored in the user profile and will follow the users roaming profile.

If  variables with the same name are stored as both  User and Machine Environment variables, the user variable will take precedence. If a Session variable is created   that will take precedence over any User and/or Machine Environment variable with the same name.

To edit environment variables in the Windows GUI: Control Panel | System | Advanced | Environment Variables

To delete an environment variable either use the GUI (recommended) or delete the value from the registry with REG delete HKCU\Environment /V _myvar Deleting a variable with REG will not take effect until next logon due to caching of registry data. Setting value of "" (empty quotes) will appear to delete the variable - it's not shown by SET but the variable name will remain in the registry.

Registry Mode

HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE are the only supported hives. REG_DWORD, REG_EXPAND_SZ, REG_SZ, and REG_MULTI_SZ are the valid RegKey data types. When reading REG_MULTI_SZ values from the registry, only the first item will be extracted and used.

File Mode

REG_DWORD registry values are extracted and used in hexadecimal mode. File mode supports the parsing of carriage return and line feed (CRLF) text files only.

Examples:
In all the examples below the variable names are prefixed with an underscore _ this is not a requirement but is a common convention to indicate a CMD variable name.

Set the variable _car_park to be 'South' in the users  environment:
SetX _car_park South

Set the variable _car_park to be 'North' in the MACHINE  environment:
SetX _car_park North /m
Store the value of _car_park in a second environment variable SetX _oldcarpark %_car_park%
Set the _car_park environment variable in the local environment to 'West' on a remote computer named Computer64:

SetX /s computer64 /u ss64dom\user64 /p P7BmqgWZ1a _car_park West

Set the _MyPath environment variable in the local environment to use the search path defined in the %PATH% environment variable:

SetX _MyPath %PATH%

Set the _MyPath environment variable in the local environment to use the search path defined in the %PATH% environment variable after replacing ~ with %:

SetX _MyPath ~PATH~

Set the _MyPath environment variable in the local environment to use the search path defined in the PATH environment variable on a remote computer named Computer64:

SetX /s computer64 /u ss64dom\user64 /p P7BmqgWZ1a _MyPath %PATH%

Set the _TZone environment variable in the local environment to the value found in the HKLM...\StandardName registry key:

SetX _TZone /k HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\StandardName

Set the _Build environment variable in the system environment to the value found in the HKLM\...\CurrentBuildNumber registry key:

SetX _Build /k "HKEY_LOCAL_MACHINE\Software\Microsoft\WindowsNT\CurrentVersion\CurrentBuildNumber" /m

To display the contents of a file named Ipconfig.out, along with the contents' corresponding coordinates:

SetX /f ipconfig.out /x

To set the _IPADDR environment variable in the local environment to the value found at the coordinate 5,11 in the file Ipconfig.out:

SetX _IPADDR /f ipconfig.out /a 5,11

To set the _OCTET environment variable in the local environment to the value found at the coordinate 5,3 in the file Ipconfig.out with delimiters "#$*.":

SetX _OCTET /f ipconfig.out /a 5,3 /d "#$*."

To set the _IPGATEWAY environment variable in the local environment to the value found at the coordinate 0,7 with respect to the coordinate of "Gateway" in the file Ipconfig.out, type:

SetX _IPGATEWAY /f ipconfig.out /r 0,7 Gateway

To display the contents of a file named Ipconfig.out — along with the contents' corresponding coordinates — on a computer named Computer64, type:

SetX /s computer64 /u maindom\hiropln /p p@ssW23 /f ipconfig.out /x

"You are never dedicated to something you have complete confidence in.   No-one is fanatically shouting that the sun is going to rise tomorrow. When people are fanatically devoted to political or religious faiths or any other kind of dogmas or goals, its always because these dogmas or goals are in doubt" ~ Robert  M Pirsig

win7Setx修改环境变量的更多相关文章

  1. window下在同一台机器上安装多个版本jdk,修改环境变量不生效问题处理办法

    window下在同一台机器上安装多个版本jdk,修改环境变量不生效问题处理办法 本机已经安装了jdk1.7,而比较早期的项目需要依赖jdk1.6,于是同时在本机安装了jdk1.6和jdk1.7. 安装 ...

  2. Linux修改环境变量的方法

    在Linux操作系统中,有时候跟着教程安装了一些软件,安装成功后,很高兴的准备运行该软件相应命令,但是偶尔会遇到”Command not found…“的提示.原因是因为你安装的软件需要设置环境变量才 ...

  3. Mac Pro 修改环境变量

    参考:Ubuntu 12 修改环境变量 [实战] 把 php.php-fpm.nginx.mysql 的相关命令路径添加到 用户环境变量 $ vim ~/.bash_profile alias ll= ...

  4. Windows系统上安装多个版本jdk,修改环境变量不生效

    本机已经安装了jdk1.6,而比较早期的项目需要依赖jdk1.5,于是同时在本机安装了jdk1.5和jdk1.6. 安装jdk1.5前,执行 java -version 得到java version ...

  5. 【转】windows7 修改环境变量 和 用不用重启电脑的讨论

      原文:http://www.cnblogs.com/zhenmingliu/archive/2013/02/21/2921396.html   先到我的电脑>属性>高级>环境变量 ...

  6. Mac下修改环境变量

    Mac下修改环境变量 如果使用默认Bash, 首先修改 ~/.bash_profile 文件,添加文件路径,比如: export PATH=~/bin:/usr/local/bin/node:~/Do ...

  7. Linux系统下修改环境变量PATH路径的三种方法

    这里介绍Linux的知识,比如把/etc/apache/bin目录添加到PATH中有三种方法,看完之后你将学会Linux系统下如何修改环境变量PATH路径,需要的朋友可以参考下 电脑中必不可少的就是操 ...

  8. 批处理,修改环境变量path的方法(加环境变量)

    方法一:批处理中,修改环境变量,一次性有效(也就是在当前的脚本中有效) CMD中运行 set path==%path%;d:/mypath 用 set path可以查看,当前的环境变量 方法二 :批处 ...

  9. linux修改环境变量

    /etc/profile 系统全局环境变量设定,所有用户共享,修改后,需要重启系统才能生效 ~/.bash_profile,~/.bashrc 用户目录下的私有环境变量设定,常用来个性化定制功能,修改 ...

随机推荐

  1. 单片机C51串口发送、接收寄存器

    所以,发送和接收寄存器可使用同一地址,编写验证程序(发送和接收是独立空间):读取一个数(1)->发送一个数(2)->再读取得1则是独立空间 不知道STM32串口寄存器和C51串口寄存器是否 ...

  2. CODEVS_1074 食物链

    #include<iostream> #include<algorithm> #include<cstring> #include<string> #d ...

  3. 【Java TCP/IP Socket】构建和解析自定义协议消息(含代码)

    在传输消息时,用Java内置的方法和工具确实很用,如:对象序列化,RMI远程调用等.但有时候,针对要传输的特定类型的数据,实现自己的方法可能更简单.容易或有效.下面给出一个实现了自定义构建和解析协议消 ...

  4. Python的未来和Python的意义 & pypy & JIT

    今天在读关于Lisp的文章,感概于这门语言的生命力(Link).同时也读到了关于python的文章,Python之父谈Python的未来(Link) 文章中拿Python和Javascript作比较, ...

  5. C语言里字符串的解析

      根据给定的字符串,按照一定规则解析字符串,卡住好几次,这次做个笔记,以供参考 函数名称:   strtok 函数原型:   char *strtok(char *s1, const char *s ...

  6. 深入JVM系列(二)之GC机制、收集器与GC调优(转)

    一.回顾JVM内存分配   需要了解更多内存模式与内存分配的,请看 深入JVM系列(一)之内存模型与内存分配 1.1.内存分配: 1.对象优先在EDEN分配2.大对象直接进入老年代 3.长期存活的对象 ...

  7. Distributed Management Task Force----分布式管理任务组

    http://baike.baidu.com/link?url=Y9HGLs8Qj6pXbbgY6xPdfiGDsQO8Eu1e80B4giQtQ_hAfGNF59byxnLoERYri4Duw7Gw ...

  8. 记录魅族m1note编译TWRP recovery 3.1.0-0,包括mtk机型的处理方法

    1.安装64位linux系统,我用的是deepin os 15.3 2.将系统升级到最新版本 sudo apt-get update && sudo apt-get upgrade 3 ...

  9. 李洪强iOS开发之-实现点击单行View显示和隐藏Cell

    李洪强iOS开发之-实现点击单行View显示和隐藏Cell 实现的效果:  .... ....

  10. (转)typedef用法

    Typedef 声明有助于创建平台无关类型,甚至能隐藏复杂和难以理解的语法.不管怎样,使用 typedef 能为代码带来意想不到的好处,通过本文你可以学习用 typedef 避免缺欠,从而使代码更健壮 ...