1 |
joko |
1.1 |
# ported from http://permalink.gmane.org/gmane.comp.python.windows/3801 |
2 |
|
|
|
3 |
|
|
import win32gui |
4 |
|
|
import win32api |
5 |
|
|
import time |
6 |
|
|
import os |
7 |
|
|
|
8 |
|
|
# send WM_QUIT to explorer - 18 == WM_QUIT |
9 |
|
|
print "Shutting down Explorer" |
10 |
|
|
try: |
11 |
|
|
hwnd = win32gui.FindWindow('Progman', None) |
12 |
|
|
win32api.PostMessage(hwnd, 18, 0, 0) |
13 |
|
|
except: |
14 |
|
|
None |
15 |
|
|
|
16 |
|
|
# wait a while for it to exit - 10 seconds, checking twice/sec |
17 |
|
|
print "Waiting for Explorer to exit" |
18 |
|
|
for retryAttempt in range(1, 10): # 5 seconds |
19 |
|
|
time.sleep(0.5) |
20 |
|
|
try: |
21 |
|
|
if win32gui.FindWindow('Progman', None) == 0: break |
22 |
|
|
except: |
23 |
|
|
None |
24 |
joko |
1.2 |
time.sleep(2) |
25 |
joko |
1.1 |
|
26 |
|
|
# explorer is dead - restart it (SW_SHOW=5) |
27 |
|
|
print "Restarting Explorer" |
28 |
|
|
#InstExec('explorer.exe', '', '', False, False, 5, errCode) |
29 |
|
|
#os.system('explorer.exe') |
30 |
|
|
os.system('start explorer.exe') |
31 |
|
|
#os.spawnl(os.P_DETACH, 'c:\\windows\\explorer.exe', 'c:\\windows\\explorer.exe') |
32 |
|
|
#os.execl('c:\\windows\\explorer.exe', 'c:\\windows\\explorer.exe') |
33 |
|
|
|
34 |
|
|
# Now a few seconds to actually start - if we don't wait for this, |
35 |
|
|
# then we may write the RunOnce keys before it has, causing |
36 |
|
|
# explorer to process them as we are still installing (or just finished). |
37 |
|
|
# Explorer processes the 'RunOnce' etc entries before creating its main window |
38 |
|
|
print "Waiting for Explorer to start" |
39 |
|
|
for retryAttempt in range(1, 20): |
40 |
|
|
time.sleep(0.5) |
41 |
|
|
if win32gui.FindWindow('Progman', None) != 0: break |
42 |
|
|
# OK, explorer is back up |