How to use the :IsFileOpen, IsRegKey, IsRegValue, IsServiceR

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mlwhitl
Posts: 1
Joined: 10 Feb 2009 07:05

How to use the :IsFileOpen, IsRegKey, IsRegValue, IsServiceR

#1 Post by mlwhitl » 10 Feb 2009 08:17

I'm looking for examples on how to use or test the results from the IsFileOpen, IsRegKey, IsRegValue, or IsServiceRunning functions.

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 20 Feb 2009 23:14

mlwhitl,

Yes, I can see it might need some more explanation...

You could check ERRORLEVEL right after calling the function or simply
use the && operator to react on success (service is running) or
use the || operator to react on failure (service not running),
like this:

Code: Select all

@Echo Off
call:IsServiceRunning "DHCP"&&echo.DHCP service is Running
call:IsServiceRunning "DHCP"||echo.DHCP service is not Running
Goto:Eof

:IsServiceRunning service -- returns success if service is running, otherwise failure
::                        -- service  [in]  - name of the service to check
:$created 20060101 :$changed 20080219 :$categories ServiceControl
:$source http://www.dostips.com
SETLOCAL ENABLEDELAYEDEXPANSION
sc query "%~1"|findstr "STATE.*:.*4.*RUNNING">NUL
EXIT /b

DOS IT HELP? :wink:

Post Reply