
%path% variable cause it reports %systemroot% as c:\windows Like this code. It do the trick but it is wrong:set add=c:\tools
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" ^
/v Path /t REG_EXPAND_SZ /d "%path%;%add%" /f
I have to play with:HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\EnvironmentWhen i query from XP it reports:


Folowing code needs:
This solution included finding duplicate entry and do not let you add existing path variable: Some explanations:
sed "s/! REG.EXE VERSION 3.0//I" deletes first founded "! REG.EXE VERSION 3.0". This is needed to support Windows XP. I - means not case sensitivesed "s/Path//I" deletes first founded "path"sed "s/REG_EXPAND_SZ//I" deletes first founded "REG_EXPAND_SZ"sed "s/HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment//I" deletes first founded"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
sed s/^[ \t]*//g" deletes all tabs and white spaces at the start of the linesed "/./!d" removes all empty lines.sed "$a;%p%" finally adds new variablesed "s/;/\n/g" substitute semicolon with new line character. It splits all variables into colonawk "!a[$0]++" since the is each variable on single line we can check for duplicate entry and remove it.sed "/./!d" - if something was found dublicated then now it is removed and there is one line witch contains nothing and this line must me removed.sed ":a;N;$!ba;s/\n/;/g" finally we substitute back again new line character with semicolon :)Note:
The
set p= variable must contains path with double backslashes likeC:\\Program Files (x86)\\GnuWin32\\bin
No comments:
Post a Comment