Tags

,

In command line, we can use Tasklist to find the process the service is running.
Tasklist /FI “SERVICES eq serviceA”

Use Taskkill to kill the process the service is running. 
Taskkill /F /FI “SERVICES eq serviceA”

We can use sc command to query the service and delete the service.
sc query serviceA
If the service doesn’t exists, it will show the following error:
[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.

sc start serviceA
sc stop serviceA
sc delete serviceA

Or we can use net start|stop serviceA to start, stop a service.

//<![CDATA[
if(showAdsense){
document.write("(adsbygoogle = window.adsbygoogle || []).push({});”)
}
//]]>

In Window Batch script, we can use SC QUERY to query a service, and check ERRORLEVEL to determine whether a service exist:
SC QUERY serviceA > NUL
REM if ERRORLEVEL 1060 means it doesn’t exists
IF ERRORLEVEL 1060 (
echo service doesn’t exist
)

Start|Stop Service in PowerShell
get-service serviceA
start-service serviceA
stop-service serviceA
restart-service serviceA

Resources
SC Command

via Blogger http://lifelongprogrammer.blogspot.com/2014/01/managing-windows-services.html

Advertisements