Radeon RX 6800 XT の OpenCL を有効化する に記述したレジストリ操作について、毎回手作業で実施することが面倒なため Python スクリプトに起こした。
#! python
import os
import winreg
base_path = r"C:\Windows\System32\DriverStore\FileRepository"
def detect_amdocl():
amdocl_list = []
for curDir, dirs, files in os.walk(base_path):
for file in files:
if not file.lower() == "amdocl64.dll":
continue
amdocl_fullpath = os.path.join(curDir, file)
amdocl_timestamp = os.stat(amdocl_fullpath).st_mtime
amdocl_list.append({'path': amdocl_fullpath, 'ts': amdocl_timestamp})
if len(amdocl_list) == 0:
return None
amdocl_list = sorted(amdocl_list, key=lambda e:e['ts'])
return amdocl_list[-1]['path']
def remove_old_values(regkey, latest_amdocl=None):
i = 0
while True:
value_name = None
try:
value_name = winreg.EnumValue(regkey, i)[0]
i += 1
except OSError:
# Will be here when the enumeration is done.
break
if not value_name.lower().endswith("amdocl64.dll"):
continue
if latest_amdocl:
if value_name.lower() == latest_amdocl.lower():
print("latest value: %s" % value_name)
continue
print("delete value: %s" % value_name)
try:
winreg.DeleteValue(regkey, value_name)
except Exception as e:
print(e)
if __name__ == "__main__":
amdocl_path = detect_amdocl()
if not amdocl_path:
raise Exception("Could not determine path of amdocl64.dll")
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE, )
regkey = winreg.OpenKey(reg, r"SOFTWARE\Khronos\OpenCL\Vendors",
0, winreg.KEY_ALL_ACCESS)
# Delete old values.
remove_old_values(regkey, amdocl_path)
# Add a new key.
winreg.SetValueEx(regkey, amdocl_path, 0, winreg.REG_DWORD, 0x00000000)
winreg.CloseKey(reg)
print("done")
PowerShell での実装がより理想的かもしれないが。今度 cxFreeze による EXE バイナリ化などを試してみようと思う。
0 件のコメント:
コメントを投稿