July 25, 200521 yr I am looking for a way I can Read a win2000/xp registry setting and set the data value as an enviroment var that can be used in a batch file script. I have check the reg.exe command but done see any method that can have the output of just the data be a VAR.Anyone know of a way?Thanks a ton.MrChris
July 25, 200521 yr @ MrChris Here is a template using reg.exe with an example added to help you understandecho off&setlocal enableextensions:: put the registry key you want to read after the equals symbol belowset keyname=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run:: put the value name of the registry key after the equals symbol belowset valuename=nwizfor /f "tokens=1,3* delims= " %%a in ('reg query %keyname%^|findstr/i "%valuename%"') do set mynewvar="%%~b"echo/you have set a new local variable named mynewvar as %mynewvar%endlocal&goto :eof NoteThe space after delims= is a Tab
July 25, 200521 yr Author @ MrChris Here is a template using reg.exe with an example added to help you understandecho off&setlocal enableextensions:: put the registry key you want to read after the equals symbol belowset keyname=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run:: put the value name of the registry key after the equals symbol belowset valuename=nwizfor /f "tokens=1,3* delims= " %%a in ('reg query %keyname%^|findstr/i "%valuename%"') do set mynewvar="%%~b"echo/you have set a new local variable named mynewvar as %mynewvar%endlocal&goto :eof NoteThe space after delims= is a Tab<{POST_SNAPBACK}>Thank you very much. That is kinda of what im looking for but only in my case the key value will always be the same name but the data that belongs to that value is what will always be diff. If that makes sense. for example.HKEY_CURRENT_USER\Software\EasyBoot Systems\UltraISO\5.0has a string name=UserName but the data for that string is always diff. I want to set the data from the value as the env. var. In your above example it was setting the value itsself as the var.I know batch scripting a little but not a lot. I only know the simple parts of it. And I know that there are a ton load of commands that can be passed in a batch file.Thanks again for the help.MrChris Edited July 25, 200521 yr by MrChris
July 25, 200521 yr Well unfortunately, your particular example may not work with the template I gave due to the space in the key name, therefore tryecho off&setlocal enableextensionsset keyname=HKCU\Software\EasyBoot Systems\UltraISO\5.0:: put the value name of the registry key after the equals symbol belowset valuename=for /f "tokens=1,3* delims= " %%a in ('reg query "%keyname%"^|findstr/i "%valuename%"') do set mynewvar="%%~b"echo/Data Value %mynewvar% is now set to variable mynewvarendlocal&goto :eofi.e. add the quotation marks to the %keyname% in your reg query command
July 25, 200521 yr Author Unless im missing something. It still is setting the var as USERNAME and not the data for the value. such as USERNAME=John Doe
July 25, 200521 yr As I do not have the application you are using, it is difficult for me to test, however, if you have ensured that the space is in fact a tab only, it should work; as should this shorter versionecho off&setlocal enableextensionsfor /f "tokens=3* delims= " %%a in ('reg query "HKCU\Software\EasyBoot Systems\UltraISO\5.0" /v UserName') do set mynewvar="%%~a"echo/you have set a new local variable named mynewvar as %mynewvar%endlocal&goto :eofmaking sure once again that delims=<Tab>If it still doesn't work try posting an output of the reg query command from a cmd session:reg query "HKCU\Software\EasyBoot Systems\UltraISO\5.0" /v UserNameYou should get an output consisting of the three tokens, 1st being your value name, 2nd being the data type and the third being the data value you require, each seperated by a tab Edited July 25, 200521 yr by Yzöwl
July 25, 200521 yr Author Ahh yes this worked just as I need. Thanks a ton. But the data of the value has spaces in it and its only getting the first part of it. None the less thanks. The output is there when the batch is done running. but when I view the var with the SET command I only see the first part of the data.I dont think this type of a task will onyl work for the app i refer too. It should work across the board. Edited July 25, 200521 yr by MrChris
July 26, 200521 yr Just as a side note, if you are wishing to add the variable to your system, i.e. always there; since the current variable is only local to the running batch.@echo off&setlocal enableextensionsfor /f "tokens=3* delims= " %%a in ( 'reg query "HKCU\Software\EasyBoot Systems\UltraISO\5.0" /v UserName^2^>nul') do ( if errorlevel 0 ( reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MyNewVar /d "\"%%~a\"" /f&&echo/you have set a new environment variable named MyNewVar ))endlocal&goto :eof
July 28, 200521 yr Just what to be sure:Why is it necessary to use space after delims? Isn't delimis space or tab by default?thanks
July 28, 200521 yr @ TakeshiI said NoteThe space after delims= is a Tabandmaking sure once again that delims=<Tab>each seperated by a tabthe space is not wanted or required
Create an account or sign in to comment