n = ctypes.windll.kernel32.GetEnvironmentVariableW(name, None, 0)
if n == 0:
    return None
buf = ctypes.create_unicode_buffer('\x00' * n)
ctypes.windll.kernel32.GetEnvironmentVariableW(name, buf, n)
return buf.value
Problems with umlauts in python appdata environvent variable