Jump to content

Adding directory to System Path via REG.EXE


daddydave

Recommended Posts

I am writing a batch file to add a directory to the Path, reg.exe style.


@echo off
rem I used DoesNothing value while testing but will use the Path value
set Sysenvt=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
for /f "tokens=3* delims= " %%f in ('reg query "%SysEnvt%" /v DoesNothing') do set Currntpth=%%f
reg add "%SysEnvt%" /v DoesNothing /t REG_EXPAND_SZ /d "%Currntpth%;%%ProgramFiles%%\Windows Resource Kits\Tools" /f

That should be a tab character after delims=.

I managed to get it working exactly the way I want, but I was wondering if it could be improved. If I do the embedded req query by itself:

reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path

One of the lines says

! REG.EXE VERSION 3.0

I'm not clear on what happens to this line, is it guaranteed to get ignored by the for /f processing?

(Testing in XP)

Link to comment
Share on other sites


Am I missing something? Why not use the %PATH% variable?

@echo off
rem I used DoesNothing value while testing but will use the Path value
set Sysenvt=HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
reg add "%SysEnvt%" /v DoesNothing /t REG_EXPAND_SZ /d "%PATH%;%%ProgramFiles%%\Windows Resource Kits\Tools" /f

I'm assuming this is still your testing code since 'DoesNothing' should be 'Path' if you are really trying to add this to the 'Path' variable.

Link to comment
Share on other sites

Am I missing something? Why not use the %PATH% variable?

I was originally trying to avoid adding a User environment var to the System environment, but now that you mention it, I'm only dealing with this one variable, and PATH seems to be pretty much always in the System environment , so that concern may be unwarranted.

Edited by daddydave
Link to comment
Share on other sites

Am I missing something? Why not use the %PATH% variable?

I was originally trying to avoid adding a User environment var to the System environment, but now that you mention it, I'm only dealing with this one variable, and PATH seems to be pretty much always in the System environment , so that concern may be unwarranted.

My way didn't work with the reg.exe version (2.0) that was made for Win2K, your way did. Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...