summaryrefslogtreecommitdiff
path: root/scripts/winservices.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-04-10 18:44:43 +0200
committerGiampaolo Rodola <g.rodola@gmail.com>2016-04-10 18:44:43 +0200
commitf5865347037b779b94d56aaf23c05d8276857a9e (patch)
tree713fe76bcfeb88f155d9ee4a5408229b6feb3f41 /scripts/winservices.py
parentfc5753fd51134d7b838ed457c2253e71090bdad1 (diff)
downloadpsutil-f5865347037b779b94d56aaf23c05d8276857a9e.tar.gz
add winservice script and disablr start() and stop() methods
Diffstat (limited to 'scripts/winservices.py')
-rw-r--r--scripts/winservices.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/winservices.py b/scripts/winservices.py
new file mode 100644
index 00000000..fed6a734
--- /dev/null
+++ b/scripts/winservices.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+List all Windows services installed.
+
+$ python scripts/winservices.py
+AeLookupSvc (Application Experience)
+status: stopped, start: manual, username: localSystem, pid: None
+binpath: C:\Windows\system32\svchost.exe -k netsvcs
+
+ALG (Application Layer Gateway Service)
+status: stopped, start: manual, username: NT AUTHORITY\LocalService, pid: None
+binpath: C:\Windows\System32\alg.exe
+
+APNMCP (Ask Update Service)
+status: running, start: automatic, username: LocalSystem, pid: 1108
+binpath: "C:\Program Files (x86)\AskPartnerNetwork\Toolbar\apnmcp.exe"
+
+AppIDSvc (Application Identity)
+status: stopped, start: manual, username: NT Authority\LocalService, pid: None
+binpath: C:\Windows\system32\svchost.exe -k LocalServiceAndNoImpersonation
+
+Appinfo (Application Information)
+status: stopped, start: manual, username: LocalSystem, pid: None
+binpath: C:\Windows\system32\svchost.exe -k netsvcs
+
+...
+"""
+
+
+import os
+import sys
+
+import psutil
+
+
+if os.name != 'nt':
+ sys.exit("platform not supported (Windows only)")
+
+
+def main():
+ for service in psutil.win_service_iter():
+ info = service.as_dict()
+ print("%s (%s)" % (info['name'], info['display_name']))
+ print("status: %s, start: %s, username: %s, pid: %s" % (
+ info['status'], info['start_type'], info['username'], info['pid']))
+ print("binpath: %s" % info['binpath'])
+ print("")
+
+
+if __name__ == '__main__':
+ sys.exit(main())