February 1, 2012 at 3:33 am
I have a file INST.txt in a folder which has got SQL instance names in it in just 3 lines. Ex :
INSTANCE1
INSTANCE2
INSTANCE3
I want to compare each of the above value to a string value in registry at : REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
If not found, I have to install that instance. Otherwise skip to next value.
I tried like below, but doesn't work. If not found in registry, i get an ERROR saying : THe system cannot find the specified value in registry. Can someone modify please. I need urgently.
for /f "tokens=1 delims=" %%b in ('type C:\MSSQL10\INST.txt') do (REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" /v "%%b")
IF %ERRORLEVEL% EQU 0 (
Echo "Instance found. Do nothing"
) else (
Echo "executing : " %%b
"C:\Inst\setup.exe"
)
)
February 1, 2012 at 3:49 am
Not really a SQL question 😛
It has been a while since I did anything like this, but I think you need to suppress the error report.
for /f "tokens=1 delims=" %%b in ('type C:\MSSQL10\INST.txt') do (REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL" /v "%%b" 1>nul 2>&1)
if errorlevel 1 (
Echo "executing : " %%b
"C:\Inst\setup.exe"
) else (
Echo "Instance found. Do nothing"
)
February 1, 2012 at 6:09 am
:hehe:
Yes you should go to vb.net forum to match your questions ,but he reply you right
:w00t:
February 1, 2012 at 6:12 am
johnitech.itech (2/1/2012)
:hehe:Yes you should go to vb.net forum to match your questions ,but he reply you right
:w00t:
What has vb.net got to do with this question?
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply