Solved

Getting return code

Posted on 2009-06-28
4
295 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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