Search for Service using Regular Expression

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sujitha
Posts: 2
Joined: 01 Dec 2014 07:22

Search for Service using Regular Expression

#1 Post by sujitha » 01 Dec 2014 10:53

I had a service. I want to know whether the service had been installed on the system or not. I can provide some part of the service name but not entirely.
I have tried couple of commands but couldn't get the result.

sc query
find
Last edited by sujitha on 01 Dec 2014 11:33, edited 1 time in total.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Search for Service using Regular Expression

#2 Post by Squashman » 01 Dec 2014 11:08

Find all services that begin with the letter W

Code: Select all

T:\>sc query | findstr /I /B /R /C:"^SERVICE_NAME: W.*"
SERVICE_NAME: W32Time
SERVICE_NAME: wcncsvc
SERVICE_NAME: WdiServiceHost
SERVICE_NAME: wdPostMan
SERVICE_NAME: WebClient
SERVICE_NAME: Winmgmt
SERVICE_NAME: Wlansvc
SERVICE_NAME: wmiApSrv
SERVICE_NAME: wscsvc
SERVICE_NAME: WSearch
SERVICE_NAME: wuauserv
SERVICE_NAME: wudfsvc

sujitha
Posts: 2
Joined: 01 Dec 2014 07:22

Re: Search for Service using Regular Expression

#3 Post by sujitha » 01 Dec 2014 11:10

I guess this commands only gets the services which are active or in started mode.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Search for Service using Regular Expression

#4 Post by Squashman » 01 Dec 2014 11:28

IF you READ the HELP file for the SC command you would see this.

Code: Select all

QUERY and QUERYEX OPTIONS:
        If the query command is followed by a service name, the status
        for that service is returned.  Further options do not apply in
        this case.  If the query command is followed by nothing or one of
        the options listed below, the services are enumerated.
    type=    Type of services to enumerate (driver, service, all)
             (default = service)
    state=   State of services to enumerate (inactive, all)
             (default = active)
    bufsize= The size (in bytes) of the enumeration buffer
             (default = 4096)
    ri=      The resume index number at which to begin the enumeration
             (default = 0)
    group=   Service group to enumerate
             (default = all groups)

SYNTAX EXAMPLES
sc query                - Enumerates status for active services & drivers
sc query eventlog       - Displays status for the eventlog service
sc queryex eventlog     - Displays extended status for the eventlog service
sc query type= driver   - Enumerates only active drivers
sc query type= service  - Enumerates only Win32 services
sc query state= all     - Enumerates all services & drivers
sc query bufsize= 50    - Enumerates with a 50 byte buffer
sc query ri= 14         - Enumerates with resume index = 14
sc queryex group= ""    - Enumerates active services not in a group
sc query type= interact - Enumerates all interactive services
sc query type= driver group= NDIS     - Enumerates all NDIS drivers



Code: Select all

sc query type= all state= all | findstr /I /B /R /C:"^SERVICE_NAME: W.*"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search for Service using Regular Expression

#5 Post by foxidrive » 01 Dec 2014 16:19

sujitha wrote:I had a service. I want to know whether the service had been installed on the system or not.


When you say installed, that implies it is currently running right?

Post Reply