import winreg
import os
def get_desktop():
subkey = r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, subkey)
(value, _) = winreg.QueryValueEx(key, 'Desktop')
return value
if __name__ == '__main__':
# 正确
print(get_desktop())
# 不正确
print(os.path.join(os.path.expanduser('~'),'Desktop'))