Last active
September 27, 2023 09:08
-
-
Save joncutrer/905f73c75d8bb12fe1d714148b58d74b to your computer and use it in GitHub Desktop.
Python: Check if Windows Service is running|installed without pywin32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import psutil | |
# | |
# Python Script to Check if... | |
# Windows Service is found|installed,stopped|running without pywin32 | |
# Found at https://stackoverflow.com/questions/33843024 | |
# Update to work on python 3.x | |
# | |
def getService(name): | |
service = None | |
try: | |
service = psutil.win_service_get(name) | |
service = service.as_dict() | |
except Exception as ex: | |
print(str(ex)) | |
return service | |
service = getService('LanmanServer') | |
print(service) | |
if service: | |
print("service found") | |
else: | |
print("service not found") | |
if service and service['status'] == 'running': | |
print("service is running") | |
else: | |
print("service is not running") |
Hi, I need little help with this code, I need to create a loop so that it will check the service after every 30 sec and if service is down it will restart that service can you help me with that.
actually i been do this script.Use thread for loop suggest in advance 😂
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I need little help with this code, I need to create a loop so that it will check the service after every 30 sec and if service is down it will restart that service can you help me with that.