Simsons
Simsons

Reputation: 12735

How to Create Registry key using a batfile

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.

Upvotes: 2

Views: 27211

Answers (4)

Javed Akram
Javed Akram

Reputation: 15344

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.........

Upvotes: 1

Joey
Joey

Reputation: 354366

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.

Upvotes: 0

Vantomex
Vantomex

Reputation: 2295

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

Upvotes: 1

Will03uk
Will03uk

Reputation: 3444

SET variable=string

Upvotes: 0

Related Questions