views:

38

answers:

4

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

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

A: 

SET variable=string

Will03uk
Environment variables (what you're setting in your example) are different from registry keys.
Chris Smith
But his main purpose is to set environment variables
Will03uk
+1  A: 

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

Vantomex
A: 

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 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.
Joey
@Joey ,It seems SETX is specific to Windows 7
Subhen
It's been in core Windows since at least Vista. Having never used XP I have no idea as how that is on legacy systems. It was part of a Resource kit previously. Furthermore, you never said anything about an OS restriction, so I assumed something recent.
Joey
A: 

Yes u can create Registry Key using Batch file

here is an example:

for disabling task manager using .bat file:

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.

Enjoy.........

Javed Akram