Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code is

Please correct that

echo Off
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MA Service"
set VALUE_NAME=DBServer 
REG QUERY %KEY_NAME% /S /v %VALUE_NAME%
endlocal



This works fine

But i want to assign value DBServer to varible



echo Off
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MA Service"
set VALUE_NAME=DBServer 
set %%Sn =for /f %%Sn in ('REG QUERY %KEY_NAME% /S /v %VALUE_NAME%') do set 
Sname=%%Sn
echo %Sname%
endlocal
pause


Please correct above command.

Thanks
Posted
Updated 19-Jan-16 20:23pm
v2

One way would be to use for loop with do set.

Try this thread for samples -
http://www.tomshardware.com/forum/230090-45-windows-batch-file-output-program-variable[^]
 
Share this answer
 
Try this,

echo Off
setlocal ENABLEEXTENSIONS
set KEY_NAME="HKLM\SYSTEM\CurrentControlSet\services\MA Service"
set VALUE_NAME=DBServer 

echo %VALUE_NAME%
echo %KEY_NAME%

FOR /F "tokens=2* delims= " %%A IN ('REG QUERY %KEY_NAME% /v %VALUE_NAME%') DO SET TMP=%%B
ECHO TMP=%TMP%

endlocal
pause
 
Share this answer
 
Comments
Mangesh9692 20-Jan-16 3:57am    
Thanks Asif it work for me
Mangesh9692 20-Jan-16 7:07am    
Hi this working fine when i ran file file from desktop,but if i put it on folder inside d drive it wont work
_Asif_ 20-Jan-16 7:11am    
how you executing it?
Mangesh9692 20-Jan-16 7:32am    
using .bat file
_Asif_ 20-Jan-16 8:21am    
Try running it using administrative privileges.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900