Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   Batch Script to Add System Variables to Registry (http://www.go4expert.com/forums/batch-script-add-variables-registry-t25230/)

Cleptography 13Mar2011 05:11

Batch Script to Add System Variables to Registry
 
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.



All times are GMT +5.5. The time now is 00:06.