Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with batch file - reg query and errorlevel  (Read 14129 times)

0 Members and 1 Guest are viewing this topic.

minnehaha

  • Guest
Help with batch file - reg query and errorlevel
« 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.

Sidewinder



    Guru

    Thanked: 124
  • Experience: Familiar
  • OS: Windows 10
Re: Help with batch file - reg query and errorleve
« Reply #1 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.

The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

minnehaha

  • Guest
Re: Help with batch file - reg query and errorleve
« Reply #2 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.

Sidewinder



    Guru

    Thanked: 124
  • Experience: Familiar
  • OS: Windows 10
Re: Help with batch file - reg query and errorleve
« Reply #3 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-)
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

minnehaha

  • Guest
Re: Help with batch file - reg query and errorleve
« Reply #4 on: February 02, 2007, 03:43:24 PM »
YES that works!!! I knew I was missing something small.

Thanks!!!!!!!!!