Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding names of services

48 views
Skip to first unread message

Tom Del Rosso

unread,
Oct 20, 2020, 10:13:42 AM10/20/20
to
If you run this:


net stop LanmanServer /y


The output is:


The following services are dependent on the Server service.
Stopping the Server service will also stop these services.

HomeGroup Listener
Computer Browser

The HomeGroup Listener service is stopping.
The HomeGroup Listener service was stopped successfully.

The Computer Browser service is stopping..
The Computer Browser service was stopped successfully.

The Server service is stopping.
The Server service was stopped successfully.


So then you want to restart the dependent services first,
and you can parse the output to get the names, but how can you translate
them into the short names?

HomeGroup Listener=HomeGroupListener
Computer Browser=Browser

It could be hard-coded but that's so...you know.

Thank you.


--



Tom Del Rosso

unread,
Oct 20, 2020, 10:40:24 AM10/20/20
to
Tom Del Rosso wrote:
>
> how can you translate them into the short names?
>
> HomeGroup Listener=HomeGroupListener
> Computer Browser=Browser


Sometimes I underestimate Microsoft. I can't help it because they
usually come up short.

But this time they did something right.

I just discovered you can use the long name with the net command if you
put the name in quotes.

Should have tried that before posting.



JJ

unread,
Oct 21, 2020, 8:10:19 AM10/21/20
to
You can use the SC tool to list the services. e.g.

sc query | find "_NAME"

Or you can use below batch file to simplify the display for easy read
format.

@echo off
setlocal enabledelayedexpansion
set n=
for /f "tokens=1,* delims= " %%A in ('sc query state^= all ^| find "_NAME"')
do (
if "%%A" == "SERVICE_NAME:" (
if "!n!" == "" (
set n=%%B
) else (
echo !n!
set n=
)
) else if "%%A" == "DISPLAY_NAME:" (
echo !n!: %%B
set n=
)
)

Robert Roland

unread,
Oct 21, 2020, 10:58:04 AM10/21/20
to
On Tue, 20 Oct 2020 10:13:39 -0400, "Tom Del Rosso"
<fizzbin...@that-google-mail-domain.com> wrote:

>how can you translate
>them into the short names?

Would a bit of PowerShell be considered cheating?

PowerShell has a feature where it can take script code directly on the
command line, so no external files are needed. Here's an example for
your specific problem:


@echo off

set service=Computer Browser

for /F "usebackq" %%n in (`powershell -command "Get-Service -Name
'%service%'|Format-Table -AutoSize -HideTableHeaders -Property name"`)
do set shortname=%%n

echo The short name is: %shortname%
--
RoRo

mokomoji

unread,
Oct 22, 2020, 6:57:05 PM10/22/20
to
2020년 10월 21일 수요일 오후 9시 10분 19초 UTC+9에 JJ님이 작성한 내용:
cmd cheating
if nand...

[source]

@echo off
cd /d "%~dp0"
setlocal
set n=
for /f "usebackq tokens=1* delims= " %%f in (`sc query state^=all^|find "_NAME:"`) do (
if /i "%%f" equ "SERVICE_NAME:" (call set "n=%%g") else (call set "n=%%n%% : %%g")&&(call echo %%n%%&call set n=)
)
pause


[/source]




npocmaka

unread,
Nov 10, 2020, 8:33:46 AM11/10/20
to
The most powerful way to search for a service name is with WMIC - even the powershell command posted above relies on WMI classes - though WMIC is a faster utility:

wmic service where "name like '%%32Time%%' and ErrorControl='Normal'" get /Format:Value
0 new messages