win7Setx修改环境变量

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 [email protected] /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修改环境变量

时间: 2024-10-14 10:49:11

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

变量的声明及其作用域、脚本、修改环境变量$PATH【:VALUE】

变量的声明及其作用域 本地变量 VARNAME=VALUE:作用域为整个bash进程[打开新的shell进程,没有该变量] [root@jiakang a]# A=123 [root@jiakang a]# bash [root@jiakang a]# echo $A [root@jiakang a]# 局部变量 local VARNAME=VALUE:作用域为当前代码段 环境变量 作用域为当前shell及其子进程[打开一个shell就是一个进程] export VARNAME=VALUE或者

Ubuntu修改环境变量PATH方法

在LINUX安装一些软件通常要添加环境变量.环境变量通俗的讲就是把程序的路径"备案"到系统中,这样执行这些程序时就不需要输入完整路径,直接在bash输入程序名就可以执行.比如常用的ls命令就是添加好了环境变量才可以直接执行ls 环境变量的名字是PATH,$符号用于读取变量的值,终端输入echo $PATH返回如下,各路径用:隔开 echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/ga

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

比如要把/etc/apache/bin目录添加到PATH中,方法有三: 1.#PATH=$PATH:/etc/apache/bin 使用这种方法,只对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效 2.#vi /etc/profile 在适当位置添加 PATH=$PATH:/etc/apache/bin (注意:= 即等号两边不能有任何空格) 这种方法最好,除非你手动强制修改PATH的值,否则将不会被改变 3.#vi ~/.bash_profile 修改PATH行,把/et

HWND_BROADCAST的一个用法——修改环境变量,立即通知系统

在编程时遇到一个问题: 就是程序通过修改注册表,修改了系统的环境变量,但是不会立即生效,除非在[我的电脑]上点击右键,然后打开环境变量的窗口,点击[OK]后,才能生效.后来用Spy++工具捕获消息,发现在点击[OK]按钮时,发送了WM_SETTINGCHANGE消息. 在网上查找原因时发现,修改了注册表之后,系统需要重启,或者向上述操作,系统才能知道注册表被修改了,之后才能生效.如果想修改完环境变量后,立即生效,需要向系统发送消息: wstring szParam = _T( "Environm

windows 安装多个版本的jdk后修改 环境变量不起作用

本机已经安装了jdk1.6,而比较早期的项目需要依赖jdk1.5,于是同时在本机安装了jdk1.5和jdk1.6. 安装jdk1.5前,执行java -version得到java version "1.6.0_38"Java(TM) SE Runtime Environment (build 1.6.0_38-b05)Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode) 安装完jdk1.5,并修改环境变量JAVA

win系统环境变量中增加或修改环境变量后快速生效

win系统环境变量中增加或修改环境变量后,需重启系统才能使之生效. 下面介绍一种方法: 以修改环境变量"PATH"为例,修改完成后,进入DOS命令提示符,输入:set PATH=C: ,关闭DOS窗口.再次打开DOS窗口,输入:echo %PATH% ,值已经生效. 不用担心DOS窗口中的修改会影响环境变量的值,DOS窗口中的环境变量只是Windows环境变量的一个副本而已.但是对副本的修改却会引发Windows环境变量的刷新,这正是我们想要的!

查看和修改环境变量PATH

echo $PATH  显示当前shell的环境变量,root用户,transfor等普通用户环境变量根据个人配置而不同.因 .bashrc 配置文件 没有设置环境变量的时候,运行命令:/usr/local/tomcat/bin/tomcat start 用export在/etc/profile中添加文件路径(对系统所有用户有效): #vim /etc/profile export PATH=/usr/local/tomcat/bin:$PATH 修改用户主目录中的隐藏文件.bashrc文件(只

InstallShield修改环境变量后不能立即生效的问题

创建一个InstallScript脚本的InstallShield安装程序,在脚本代码中更新环境变量,更新后发现注册表和计算机->属性->高级->环境变量中的变量值都更新了,但是使用命令行(WIN+R,CMD)始终获取不到设置的环境变量. 出现这个问题的原因是脚本代码中更新环境变量时没有给windows系统发送更新的通知事件.虽然网上有很多该问题的解决办法,但是我做了很多遍都不正确.最后在InstallShield自带的帮助文档中(搜索"Environment Variable

安装交叉编译工具arm-linux-gcc-4.3.2 并且修改环境变量

安装交叉编译工具arm-linux-gcc-4.3.2 2011-07-08 00:55:28|  分类: 嵌入式|举报|字号 订阅 环境:Fedora 9 STEP 1: 下载arm-linux-gcc-4.3.2.tgz. 把arm-linux-gcc-4.3.2.tgz随便放在一个目录,我放在了/opt.下载网站1:http://www.arm123.com.cn/linux/arm-linux-gcc-4.3.2.tgz             下载网站2:http://www.arm9