3

I have a registry key that contains information for a program that I am running. I have registry key exported to a directory and I can easily import using the regedit Import function. I am having trouble writing a script that does the same using python..

I can read existing keys using the following:

    import _winreg as wreg
    test = wreg.OpenKey(wreg.HKEY_CURRENT_USER, r'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer', 0, wreg.KEY_READ)
    print test

But where I'm having trouble is Importing the key from the directory on my desktop.

1
  • 4
    import subprocess; subprocess.call(['reg','import',filename]) Commented Aug 27, 2017 at 10:31

2 Answers 2

2

Xmcp's comment was actually the answer:

import subprocess
subprocess.call(['reg', 'import', filename])
Sign up to request clarification or add additional context in comments.

Comments

0

The other answer does not work if you are lacking permissions to edit the key in question. To trigger the UAC popup asking if you want to run as admin, execute the Powershell command

Start-Process reg -ArgumentList "import <filename>" -Verb RunAs

or in Python:

import subprocess
subprocess.run(['powershell.exe', 'Start-Process', 'reg', '-ArgumentList', f'"import {filename}"', '-Verb', 'RunAs']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.