windows 如何使用bat文件创建注册表项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4041998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:41:37  来源:igfitidea点击:

How to Create Registry key using a batfile

windowsregistrybatch-file

提问by Simsons

Need to Create a Registry Key using bat file.Can I create Reg Key using Command prompt or a bat file.

需要使用 bat 文件创建注册表项。我可以使用命令提示符或 bat 文件创建注册表项吗?

The main purpose behind this , I want to create envtheitroadment variable using bat file.

这背后的主要目的是,我想使用 bat 文件创建环境变量。

采纳答案by Vantomex

You can use the Windows built-in command line tools, either regedit.exeor reg.exe, see:

您可以使用 Windows 内置命令行工具,regedit.exe或者reg.exe,请参阅:

回答by Javed Akram

Yes u can create Registry Key using Batch file

是的,您可以使用批处理文件创建注册表项

here is an example:

这是一个例子:

for disabling task manager using .bat file:

使用 .bat 文件禁用任务管理器:

reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /f /v DisableTaskMgr /t REG_DWORD /d 1

for enabling task manager:

启用任务管理器:

reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /f

You can take Help by entering reg/? in command prompt for various options.

您可以通过输入 reg/? 在各种选项的命令提示符下。

Enjoy.........

享受.........

回答by Joey

If you want to create a persistent environment variable (i.e. one that not only applies to the current session) you can use setx. No need to mess around with the registry directly if there is a program to do it for you:

如果您想创建一个持久性环境变量(即不仅适用于当前会话的环境变量),您可以使用setx. 如果有程序可以为您完成,则无需直接处理注册表:

SetX has three ways of working:

Syntax 1:
    SETX [/S system [/U [domain\]user [/P [password]]]] var value [/M]

Syntax 2:
    SETX [/S system [/U [domain\]user [/P [password]]]] var /K regpath [/M]

Syntax 3:
    SETX [/S system [/U [domain\]user [/P [password]]]]
         /F file {var {/A x,y | /R x,y string}[/M] | /X} [/D delimiters]

Description:
    Creates or modifies environment variables in the user or system
    environment. Can set variables based on arguments, regkeys or
    file input.

回答by Will03uk

SET variable=string

SET 变量=字符串