0

We have an application that parses the output of sc qdescription <service_name> to get the service description, and the usual output is something like:

C:\>sc qdescription WSearch
[SC] QueryServiceConfig2 SUCCESS

SERVICE_NAME: WSearch
DESCRIPTION:  Provides content indexing, property caching, and search results for files, e-mail, and other content.

However, we just discovered that depending on the OS language, the output can be different, e.g. in German:

C:\>sc qdescription WSearch
[SC] QueryServiceConfig2 ERFOLG

SERVICE_NAME: WSearch
BESCHREIBUNG:  Stellt Inhaltsindizierung und Eigenschaftenzwischenspeicherung und Suchergebnisse für Dateien, E-Mails und andere Inhalte bereit.

My question is:

  • Which criteria should be used to extract the description? The second occurrence of the text after the :?
  • What about other languages, e.g. Arabic or Chinese?
Ahmed Ashour
  • 2,350
  • 2
  • 14
  • 21
  • There are other ways, see [this Q&A](https://superuser.com/questions/902809/how-do-i-extract-a-list-of-services-and-what-account-they-run-as) Here a wmic query: `wmic service where Name='WSearch' get name,caption,description /format:csv` either parse the csv output directly or first save to a file. – LotPings Feb 28 '19 at 15:19
  • @LotPings: thanks a lot, please post this as an answer – Ahmed Ashour Mar 04 '19 at 10:13

1 Answers1

2

As mentioned in my comment, there are other ways.

Using Service Wuauserv instead of Wsearch

A wmic query with output formatted as csv has the disadvantage that the values are NOT double quoted, so parsing get's difficult when the description also contains commas.

wmic service where Name='Wuauserv' get name,caption,description /format:csv

The object oriented powershell doesn't have this problem:

(Get-Wmiobject win32_service | Where Name -eq 'Wuauserv').Description

The same wrapped into a batch file:

@Echo off
for /F "usebackq delims=" %%A in (`
  powershell -NoP -C "(get-wmiobject win32_service|Where Name -eq 'Wuauserv').Description"
`) do set "Description=%%A"
set Description

Sample output (German locale)

>set Description
Description=Erkennung, Herunterladen und Installation von Updates für Windows und andere Programme. Wenn der Dienst deaktiviert ist, können "Windows Update" bzw. das Feature "automatische Updates" nicht verwendet werden. Außerdem können Programme dann die Windows Update Agent-Programmierschnittstelle (WUA API) nicht verwenden.

LotPings
  • 7,011
  • 1
  • 15
  • 29