Python で作成しているインストーラーで小さな問題が発生しています。キーの位置に基づいてキーの値を返す関数があります。
def CheckRegistryKey(registryConnection, location, softwareName, keyName):
'''
Check the windows registry and return the key value based on location and keyname
'''
try:
if registryConnection == "machine":
aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
elif registryConnection == "user":
aReg = ConnectRegistry(None,HKEY_CURRENT_USER)
aKey = OpenKey(aReg, location)
except Exception, ex:
print ex
return False
try:
aSubKey=OpenKey(aKey,softwareName)
val=QueryValueEx(aSubKey, keyName)
return val
except EnvironmentError:
pass
場所が存在しない場合、エラーが発生します。関数が返されるようにしたいFalse
ので、場所が存在しない場合はソフトウェアインストーラーを実行できますが、ビットは常に例外になります
# check if the machine has .VC++ 2010 Redistributables and install it if needed
try:
hasRegistryKey = (edit_registry.CheckRegistryKey("machine", r"SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\VC\VCRedist", "x86", "Installed"))
if hasRegistryKey != False:
keyCheck = (edit_registry.CheckRegistryKey("machine", r"SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\VC\VCRedist", "x86", "Installed"))[0]
if keyCheck == 1:
print 'vc++ 2010 redist installed'
else:
print 'installing VC++ 2010 Redistributables'
os.system(productsExecutables + 'vcredist_x86.exe /q /norestart')
print 'VC++ 2010 Redistributables installed'
except Exception, ex:
print ex
コードを実行したときに発生する例外は
'NoneType' object has no attribute '___getitem___'
def CheckRegistryKey
関数から得られるエラーは
[Error 2] The system cannot find the file specified
私がする必要があるのは、レジストリ キーまたは場所が存在するかどうかを確認することです。そうでない場合は、実行可能ファイルに直接指定します。どんな助けでも大歓迎です。
ありがとうございました