Batch Script to Add System Variables to Registry

Discussion in 'Programming' started by Cleptography, Mar 12, 2011.

  1. Cleptography

    Cleptography New Member

    Joined:
    Sep 2, 2010
    Messages:
    39
    Likes Received:
    7
    Trophy Points:
    0
    Just a simple batch that shortens up the reg.exe add command to add system variables to the windows registry. I will probably add some more options to specify string types and the ability to add extensions and paths to already existing variables, but this works for now.
    Code:
    @echo off
     EndLocal
    
    ::##########################################################
    ::ScriptName........: AddVars.bat
    ::ScriptPurpose.....: Adds System Variables to the Registry
    ::Required Files....: Reg.exe
    ::Date..............: 03/11/2011
    ::Time..............: 19:38:44.24
    ::Requirements......: System Reboot
    ::Syntax............: AddVars.bat TestVar="C:\Program Files"
    ::Notes.............: Must be ran with elevated privilages
    ::##########################################################
    
    REM Check User Args
    if [%1]==[] goto :Usage
    
    REM Set Variables
    set Value=%1
    set Type=REG_SZ
    set Data=%2
    
    REM Add Values to the Registry
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /f /v %Value% /t %Type% /d %Data%
    
    :Usage
    REM Syntax and Usage Information
    echo.Usage:    %0 [Variable]=[Value]
    echo.
    echo.Examples: %0 TestVar=%SystemRoot%\system32\calc.exe
    echo.          %0 "Test Var"="%ProgramFiles%\My Directory"
    echo.
    echo.Adds system variables to the windows registry.
    echo.Requires a reboot of the system to take affect.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice