This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregcheck.py
124 lines (111 loc) · 3.37 KB
/
regcheck.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# This module is very old and useless in this day and age! It will be
# removed in a few years (ie, 2009 or so...)
import warnings
warnings.warn("The regcheck module has been pending deprecation since build 210",
category=PendingDeprecationWarning)
import win32con
import regutil
import win32api
import os
import sys
def CheckRegisteredExe(exename):
try:
os.stat(win32api.RegQueryValue(regutil.GetRootKey() , regutil.GetAppPathsKey() + "\\" + exename))
# except SystemError:
except (os.error,win32api.error):
print("Registration of %s - Not registered correctly" % exename)
def CheckPathString(pathString):
for path in pathString.split(";"):
if not os.path.isdir(path):
return "'%s' is not a valid directory!" % path
return None
def CheckPythonPaths(verbose):
if verbose: print("Python Paths:")
# Check the core path
if verbose: print("\tCore Path:", end=' ')
try:
appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
except win32api.error as exc:
print("** does not exist - ", exc.strerror)
problem = CheckPathString(appPath)
if problem:
print(problem)
else:
if verbose: print(appPath)
key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath", 0, win32con.KEY_READ)
try:
keyNo = 0
while 1:
try:
appName = win32api.RegEnumKey(key, keyNo)
appPath = win32api.RegQueryValue(key, appName)
if verbose: print("\t"+appName+":", end=' ')
if appPath:
problem = CheckPathString(appPath)
if problem:
print(problem)
else:
if verbose: print(appPath)
else:
if verbose: print("(empty)")
keyNo = keyNo + 1
except win32api.error:
break
finally:
win32api.RegCloseKey(key)
def CheckHelpFiles(verbose):
if verbose: print("Help Files:")
try:
key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
except win32api.error as exc:
import winerror
if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
raise
return
try:
keyNo = 0
while 1:
try:
helpDesc = win32api.RegEnumKey(key, keyNo)
helpFile = win32api.RegQueryValue(key, helpDesc)
if verbose: print("\t"+helpDesc+":", end=' ')
# query the os section.
try:
os.stat(helpFile )
if verbose: print(helpFile)
except os.error:
print("** Help file %s does not exist" % helpFile)
keyNo = keyNo + 1
except win32api.error as exc:
import winerror
if exc.winerror!=winerror.ERROR_NO_MORE_ITEMS:
raise
break
finally:
win32api.RegCloseKey(key)
def CheckRegisteredModules(verbose):
# Check out all registered modules.
k=regutil.BuildDefaultPythonKey() + "\\Modules"
try:
keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
print("WARNING: 'Modules' registry entry is deprectated and evil!")
except win32api.error as exc:
import winerror
if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
raise
return
def CheckRegistry(verbose=0):
# check the registered modules
if verbose and 'pythonpath' in os.environ:
print("Warning - PythonPath in environment - please check it!")
# Check out all paths on sys.path
CheckPythonPaths(verbose)
CheckHelpFiles(verbose)
CheckRegisteredModules(verbose)
CheckRegisteredExe("Python.exe")
if __name__=='__main__':
if len(sys.argv)>1 and sys.argv[1]=='-q':
verbose = 0
else:
verbose = 1
CheckRegistry(verbose)