how to stop/start a windows service in cmd with just a fragment of the service name. Example:
NET STOP *part_of_name_of_service*
NET START *part_of_name_of_service*
For example. mysql has many versions of "the name of service".
MySQL57
wampmysqld
etc, etc, etc
The idea is to stop/start any service that contains the word "mysql". Something like that:
net start *MySQL*
But unfortunately my attempt generates error: "The service name is not valid".
Attempts:
1.Dump service names to a file with the following command:
REG QUERY "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services" > services.txt
findstr /i /r "mysql" services.txt
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\MySQL
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\wampmysqld64
but I could not complete the loop
2.With taskkill
call :winservices "*mysql*"
:: funcion winservices
@echo off
goto:eof
:winservices
set winservices=%1
taskkill /f /im "%winservices%" /t
goto:eof
But "*mysql*"
not works (only "mysql*"
works)
The same happens when trying to delete the service:
sc delete *MySQL*
how I do this?
Very simple with PowerShell:
Start-Service
andRemove-Service
work the same, the latter is only available from PowerShell 6 onwards.found a solution here (only for kill service)