Solved

Getting return code

Posted on 2009-06-28
4
297 Views
Last Modified: 2012-05-07
Hi guys,

I have a really simple batch file.
I know that
reg query has the following return codes:
0 - Successful
1 - Unsuccessful.

--------------------------------------------- querykey.bat serverA

reg query \\%1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EnterceptAgent

When i run the above, the output i get is:

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EnterceptAgent
    Start       REG_DWORD       0x2

But what i want is the following:

This key exists.
This key does not exist.

Any help guys.
Im assuming i first have to get the return code?
Any help greatly appreciated.
0
Comment
Question by:Simon336697
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
t0t0 earned 250 total points
ID: 24734017
will this work for you?


reg query \\%1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EnterceptAgent | find /i "start"
if %errorlevel%==0 (
   echo This key exists
) else (
   echo This key does not exist
)

Open in new window

0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 250 total points
ID: 24734173
If the EnterceptAgent key does not exist then a query of it will return errorlevel 1 anyway, i.e. just simple entry as below.  If you need to check for the Start value under that key existing then you have an answer above or you can use the /v parameter:

reg query \\%1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EnterceptAgent
if %errorlevel%==1 echo Key does not exist

reg query \\%1\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EnterceptAgent /v Start
if %errorlevel%==1 echo Start DWORD does not exist

regards


Steve
0
 
LVL 1

Author Comment

by:Simon336697
ID: 24749459
Guys really appreciate all your kind help. I will split the points if it is ok.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24749528
No problem here, glad it helped.

Steve
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question