

def set_env(name, value, current=True):
    'Set HKCU/HKLM environment variables'
    root = (winreg.HKEY_CURRENT_USER if current else winreg.HKEY_LOCAL_MACHINE)
    key = winreg.OpenKey(root, 'Environment')
    try:
        (_x, key_type) = winreg.QueryValueEx(key, name)
    except WindowsError:
        key_type = winreg.REG_EXPAND_SZ
    key = winreg.OpenKey(root, 'Environment', 0, winreg.KEY_SET_VALUE)
    winreg.SetValueEx(key, name, 0, key_type, value)
    from win32gui import SendMessageTimeout
    from win32con import HWND_BROADCAST, WM_SETTINGCHANGE, SMTO_ABORTIFHUNG
    SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 'Environment', SMTO_ABORTIFHUNG, 5000)

dataset/ETHPy150Open winpython/winpython/winpython/utils.py set_env/original