Page 1 of 1

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

Posted: 10 Feb 2009 08:17
by mlwhitl
I'm looking for examples on how to use or test the results from the IsFileOpen, IsRegKey, IsRegValue, or IsServiceRunning functions.

Posted: 20 Feb 2009 23:14
by DosItHelp
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: