JSI Tip 1606. Start/Stop/Pause/Continue/List the status of local or remote Drivers and Services.


In tip 0324, I casually mentioned (and linked) to the drv and svc freeware that can accomplished the subject actions.

The usage of drv is:


usage: drv \[-acdhlLpst?\] \[-m Server\] \[Driver\] \[Driver Arguments\]

  Options:
    a  - List all drivers.
    c  - Continue, (Restart), the specified driver.
    d  - List detailed information about the specified driver.
    h  - Help, (this).
    l  - List active drivers.
    L  - List inactive drivers.
    p  - Pause the specified driver.
    s  - Start the specified driver.
    t  - Stop the specified driver.
    ?  - Usage.
    m  - Specify a Server to act on.

    Driver -
    The driver to start, stop, pause or continue. This is the Driver
    name, not the Driver Display Name.

    Driver Arguments-
    The arguments to pass to the driver, (Start only).

With no arguments, drv lists the started drivers on the local system. If
only a driver name is specified, then the status of that driver is
displayed.
The usage of svc is:
usage: svc \[-acdhlLpst?\] \[-m Server\] \[Service\] \[Service Arguments\]

  Options:
    a  - List all services.
    c  - Continue, (Restart), the specified service.
    d  - List detailed information about the specified service.
    h  - Help, (this).
    l  - List active services.
    L  - List inactive services.
    p  - Pause the specified service.
    s  - Start the specified service.
    t  - Stop the specified service.
    ?  - Usage.
    m  - Specify a Server to act on.

    Service -
    The service to start, stop, pause or continue. This is the Service
    name, not the Service Display Name.

    Service Arguments-
    The arguments to pass to the service, (Start only).

With no arguments, svc lists the started services on the local system. If
only a service name is specified, then the status of that service is
displayed.
The only difficulty with these routines is that they do not set %ERRORLEVEL%, so testing the State: of a driver or service is not easy. Here is drvsvc.bat which will set %ERRORLEVEL%:

Usage: drvsvc program object \[computer\]

where:

program is drv or svc (or the full path name).

object is the driver or service whose State: you wish to translate.

computer is the optional computer name of a remote computer where the object resides.

drvsvc.bat contains:

@echo off
if "%3"

"" goto local FOR /F "Tokens=2 Delims=- " %%i in ('%1 -m %3 %2') do set state=%%i goto test :local FOR /F "Tokens=2 Delims=- " %%i in ('%1 %2') do set state=%%i :test set ERRORLEVEL=4 if /i "%state%"

"Running" set ERRORLEVEL=1&goto end if /i "%state%"

"Stopped" set ERRORLEVEL=2&goto end if /i "%state%"

"Paused" set ERRORLEVEL=3 :end
NOTE: The state environment variable is also returned.
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish