Solved

Getting return code

Posted on 2009-06-28
4
293 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
Comment Utility
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
Comment Utility
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
Comment Utility
Guys really appreciate all your kind help. I will split the points if it is ok.
0
 
LVL 43

Expert Comment

by:Steve Knight
Comment Utility
No problem here, glad it helped.

Steve
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now