?
Solved

Getting return code

Posted on 2009-06-28
4
Medium Priority
?
301 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 1000 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 1000 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

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
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 …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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