'Registry query not working with subprocess command

When I enter this in my CMD, it works fine:

reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v BackupProductKeyDefault

However when I run the exact same command with subprocess in python, such as:

import subprocess

command = f'reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v BackupProductKeyDefault'

print(subprocess.check_output(commmand))

It gives me this error (I made it shorter to make it more readable):

ERROR: The system was unable to find the specified registry key or value. Traceback (most recent call last):

lib\subprocess.py", line 420, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,

lib\subprocess.py", line 524, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError:

Command 'reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v BackupProductKeyDefault' returned non-zero exit status 1.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source