如何从系统中删除配置环境变量有一个批处理文件 [英] How to remove an environment variable from the system configuration with a batch file

查看:207
本文介绍了如何从系统中删除配置环境变量有一个批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从客户机工作站删除系统变量。我有500多个客户,所以我想提供批处理文件用户运行自己删除系统变量。


解决方案

 你可能想使这两个永久与SETX但显然没有必要    C:\\>设置UVAR = HKCU \\环境
    C:\\>    C:\\>设置无功= HKLM \\系统\\ CurrentControlSet \\控制\\会话管理\\环境
    C:\\>

一些术语结果
在一个密钥(这就像一个文件夹),你有像一些数据的变量= 5

http://msdn.microsoft.com/en-us/library/ 3dwk5axy.aspx
有关名称会谈(a)具有值(5)。

注册表术语看起来MSDN上有点不同,但REG.EXE和维基百科似乎是一致的。
维基百科 http://en.wikipedia.org/wiki/Windows_Registry 说,所以它
注册表值存储的密钥内的名称/数据对
名称/数据对会谈。名称(一个)数据(5)和一对一起为一个值

REG似乎使用/ V这可能指的是变量的名称和它的数据(如维基百科),但它同时显示变量的名称和它的数据。和Reg有,我想是仅仅是数据的A / D。

与SETX一个例子

  C:\\>章查询%UVAR%
    HKEY_CURRENT_USER \\环境
        TEMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
        TMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
        ...C:\\> SETX AAA级3C:\\>章查询%UVAR%HKEY_CURRENT_USER \\环境
    TEMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    TMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    ...
    AAA REG_SZ 3

如果您尝试使用SETX删除它,你可以得到的最接近的是清除它,因为这MS KB文章的此MS知识库文章195050 说这让你用它仍然在注册表中。

SETX不是从注册表中删除变量

  C:\\> SETX AAA成功:指定的值保存。C:\\>章查询%UVAR%HKEY_CURRENT_USER \\环境
    TEMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    TMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    ...
    AAA REG_SZ
C:\\>

值得注意的,虽然,这个变量就CMD提示符而言不见了。回声%AAA%,因此变量不见了将显示AAA%%。这里还有在注册表中一些不必要的垃圾了。

用户发出一个有趣的问题,现在,当您尝试设置一个全系统的变量,这是行不通的。因为它被由什么是在用户变量覆盖,在这种情况下,它将始终上来为未定义

  C:\\>删除章%UVAR%/ V AAA
删除注册表值AAA(是/否)? ÿ
操作已成功完成。C:\\>

注意,AAA现在已经没有了。下文。

  C:\\>章查询%UVAR%HKEY_CURRENT_USER \\环境
    TEMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    TMP REG_EXPAND_SZ%USERPROFILE%\\应用程序数据\\本地的\\ Temp
    ...
C:\\>

如果你想要做一个系统/机环境变量而不是用户的。

下面-the线必须从管理特权的命令提示符结果
-notice关键是HKLM \\系统\\ CurrentControlSet \\控制\\会话管理\\环境结果
-The%无功%(不像%UVAR%)报价需要绕着它就算是关键中有一个空格。如果你错过了引号这没什么大不了的,你只得到这可能会提醒您使用引号错误。结果
当然-and,如果你想在SETX注册表中的一部分来设置环境变量,例如使用SETX AAA 5 -m即-m后。

  C:\\>设置无功= HKLM \\系统\\ CurrentControlSet \\控制\\会话管理\\环境C:\\>删除章无功%%/ V AAA
删除注册表值AAA(是/否)? ÿ
操作已成功完成。C:\\>

进一步注意结果
你也许能够创造只是REG环境变量添加或删除REG。(到位SETX),但无论哪种方式,设置一个变量,当你可能需要使用设置了,所以它被设置为当前会话太不只是下一个。并重新SETX链接<一个href=\"http://superuser.com/questions/647505/set-enviroment-variable-setx\">http://superuser.com/questions/647505/set-enviroment-variable-setx

I need to remove system variables from client workstations. I have 500+ clients, so I want to provide batch file to user to run himself to delete the system variables.

解决方案

You may want to make these two permanent with setx but obviously no need to

    C:\>set uvar=HKCU\Environment
    C:\>

    C:\>set mvar=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    C:\>

Some terminology
Within a Key(which is like a folder), you have a variable with some data like a=5

http://msdn.microsoft.com/en-us/library/3dwk5axy.aspx talks about name(a) having a value(5).

Registry terminology looks a bit different on msdn but reg.exe and wikipedia seem consistent. wikipedia http://en.wikipedia.org/wiki/Windows_Registry says so it "Registry values are name/data pairs stored within keys" talks of a name/data pair. name(a) data(5) and the pair together being a value.

REG seems to use /v which probably refers to both variable name and its data (as in wikipedia), it does show both the variable name and its data. And REG has a /d which I suppose is for just data.

An example with setx

   C:\>reg query %uvar%
    HKEY_CURRENT_USER\Environment
        TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
        TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
        ...



C:\>setx aaa 3

C:\>reg query %uvar%

HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    ...
    aaa    REG_SZ    3

If you try to use setx to remove it, the closest you can get is clearing it as this MS KB article this MS KB article 195050 says which leaves you with it still in the registry.

setx not removing the variable from the registry

C:\>setx aaa ""

SUCCESS: Specified value was saved.

C:\>reg query %uvar%

HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    ...
    aaa    REG_SZ


C:\>

It's worth noting though, that the variable is gone as far as the cmd prompt is concerned. echo %aaa% will display %aaa% so the variable is gone. There's just some unnecessary junk in the registry now.

user makes an interesting point, that now when you try to set a system wide variable, it doesn't work. as it gets overwritten by what is in the user variable, in this case, it will always come up as undefined.

C:\>reg delete %uvar% /v aaa
Delete the registry value aaa (Yes/No)? y
The operation completed successfully.

C:\>

Notice that aaa is now gone. Below.

C:\>reg query %uvar%

HKEY_CURRENT_USER\Environment
    TEMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    TMP    REG_EXPAND_SZ    %USERPROFILE%\AppData\Local\Temp
    ...


C:\>

If you want to do it for a system/machine environment variable rather than a user one.

-the lines below must be from an administrative privileged cmd prompt
-notice the key is HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
-The %mvar% (unlike %uvar%) needs quotes round it 'cos the key has a space in it. If you miss the quotes it's no big deal you just get an error which might remind you to use quotes.
-And of course if you want to set an environment variable in that part of the registry with setx, use e.g. setx aaa 5 -m i.e. the -m after.

C:\>set mvar=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

C:\>reg delete "%mvar%" /v aaa
Delete the registry value aaa (Yes/No)? y
The operation completed successfully.

C:\>

further note
You might be able to create an environment variable just with REG ADD or REG DELETE..(in place of setx) but either way, when setting a variable you may want to use set too, so that it is set for the current session too not just the next one. And a link re setx http://superuser.com/questions/647505/set-enviroment-variable-setx

这篇关于如何从系统中删除配置环境变量有一个批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆