import subprocess
keyPath = r'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI'
output = subprocess.run(
['reg', 'query', keyPath, '/reg:64', '/v', 'LastLoggedOnDisplayName'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='cp866')
print('stdout:', output.stdout)
print('stderr:', output.stderr)