S
S
semen79072019-12-17 12:40:22
Python
semen7907, 2019-12-17 12:40:22

Works in CMD but doesn't work in Python?

Tell me why the request in Python may not work, it gives the error "the specified key or parameter in the registry cannot be found"
Python:

import subprocess

keyPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI"
output = subprocess.run(["reg","query",keyPath,"/v","LastLoggedOnDisplayName"])
print(output.stdout)

And if I enter the same query in cmd, then everything works and I get the result.
cmd:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" /v LastLoggedOnDisplayName

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Grebenshchikov, 2019-12-17
@semen7907

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)

P
paran0id, 2019-12-17
@paran0id

> Microsoft\Windows
backslash lost

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question