Solved

Getting return code

Posted on 2009-06-28
4
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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