-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown.py
More file actions
executable file
·77 lines (66 loc) · 2.34 KB
/
shutdown.py
File metadata and controls
executable file
·77 lines (66 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Copyright 2006, Joe Hildebrand
#
# This file is part of Exodus.
#
# Exodus is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Exodus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Exodus; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import win32gui, win32api, win32process, win32con
import sys, time
def isDelphi(pid):
h = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, 0, pid)
for mod in [win32process.GetModuleFileNameEx(h, x) for x in
win32process.EnumProcessModules(h)]:
if 'delphi32.exe' in mod:
return True
return False
# clean up old restart records
key = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER, "Software")
key = win32api.RegOpenKey(key, "Jabber")
key = win32api.RegOpenKey(key, "Exodus")
try:
restart = win32api.RegOpenKey(key, "Restart")
keys = []
for i in range(0, win32api.RegQueryInfoKey(restart)[0]):
keys.append(win32api.RegEnumKey(restart, i))
for subkey in keys:
win32api.RegDeleteKey(restart, subkey)
win32api.RegCloseKey(restart)
win32api.RegDeleteKey(key, "Restart")
except:
pass
count = 0
while True:
if count > 10:
print "Could not shut down an Exodus instance"
sys.exit(1)
wins = []
last = 0
while True:
try:
win = win32gui.FindWindowEx(0, last, "TFrmExodus", None)
except:
sys.exit(0)
if win == 0:
break
pid = win32process.GetWindowThreadProcessId(win)[1]
if not isDelphi(pid):
wins.append(win)
last = win
if len(wins) == 0:
sys.exit(0)
if count > 0:
time.sleep(1)
for win in wins:
win32gui.SendMessage(win, 6374, 0, 0)
count += 1