Computer Hope

Microsoft => Microsoft DOS => Topic started by: minnehaha on February 02, 2007, 01:00:36 PM

Title: Help with batch file - reg query and errorlevel
Post by: minnehaha on February 02, 2007, 01:00:36 PM
Hello,

I am trying to have this batch file check the presence of registry entries.  I do not want it to print anything to the screen.  If the value is present I want it to print to a text file.

reg query hkcu\software\sample
if errorlevel=0 echo "hkcu\software\sample">>list.txt

That is what I have so far.

Any advice would be greatly appreciated.
Title: Re: Help with batch file - reg query and errorleve
Post by: Sidewinder on February 02, 2007, 01:57:28 PM
If all you want in your output file is "hkcu\software\sample" then you're all set and you don't even need the reg utility!

I suspect you want the result of the query in your output file:

Code: [Select]
reg query "hkcu\software\sample" >> list.txt

Hope this helps. 8-)

Not even sure the reg utility assigns errorlevels.

Title: Re: Help with batch file - reg query and errorleve
Post by: minnehaha on February 02, 2007, 02:44:21 PM
I do not want the results printed.  errorlevel 0 means that it found the reg key and errorlevel 1 means the key is missing.  It the key exists, I want the name of the key printed in the text file.

Right now what I listed gives me what I want but TOO MUCH - is there a way I can have the result of the query not printed to the screen or a file but still access the errorlevel?  The results of the query are printed to the screen but that clutters the screen.
Title: Re: Help with batch file - reg query and errorleve
Post by: Sidewinder on February 02, 2007, 02:49:26 PM
Code: [Select]
reg query hkcu\software\sample > nul
if errorlevel 0 echo "hkcu\software\sample">>list.txt

 8-)
Title: Re: Help with batch file - reg query and errorleve
Post by: minnehaha on February 02, 2007, 03:43:24 PM
YES that works!!! I knew I was missing something small.

Thanks!!!!!!!!!