Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

check if service is running ...

Publié le par damcuvelier

1) BATCH:
check if service (param %1 of batch script) is running in windows:

@echo off
sc query type= service "%1" | findstr STATE | findstr RUNNING>NUL
if "%ERRORLEVEL%"=="0" goto active
goto inactive


:inactive
echo service %1 is inactive
goto end

:active
echo service %1 is active
goto end

:end


2) Powershell:
 

check if service (param %1 of ps1 script) is running in windows:
param($ServiceName)
if(Get-Service -Name $ServiceName | where {$arrService.Status -ne "Running"}){Write-Host "service $ServiceName is Running"}else{Write-Host "service $ServiceName is not Running"}

3) Python:
check if service (param SvcName of python script) is running in all OS:
(NOT TESTED: i do not get all OS ;) )

import argparse;parser = argparse.ArgumentParser();parser.add_argument("SvcName");args = parser.parse_args();ServiceNamecName = args.SvcName
import psutil;ServiceNamecName in (p.name() for p in psutil.process_iter())

 

Commenter cet article