Bottom Page

Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Issues with running regedit command from python
#1
I've been working on a script for someone and they need the Windows registry backed up before the script is run.  I've been using the code below, but I recently noticed that it's not getting all of the registry backup.  I added the check=True argument to see if it would raise an error, but no error was raised.  When I run the command in the regular command prompt window, I end up with a 194MB file.  However, when I run the same command using the code below, I end up with a 117MB file.  Any suggestions on how the file could be cut short like that?

    def backup_registry(self) -> None:
        try:
            print("Backing up the registry.")
            cmd = "regedit.exe /a /e " + self.write_path + "EntireRegistry.reg"
            subprocess.run(cmd, check=True)
        except subprocess.CalledProcessError:
            raise
Quote
#2
You might want to take a look at regobj so that you have more control over the process.
see: https://pypi.python.org/pypi/regobj/0.2.2
Using a command call could be a security issue.
metulburr and gohanzdad like this post
Quote
#3
Would it be possible for you to point me toward some examples of the code usage?  Maybe something that shows iterating over the entire registry?
Quote
#4
Here's one example: https://github.com/jeffbryner/pyioc/blob...tryItem.py
There is also a use in this package: https://pypi.python.org/packages/source/...1.3.tar.gz module: pysel.py
I can't vouch for either of these, but can't find a lot either.

A good place to search for python examples for anything is http://nullege.com/
gohanzdad likes this post
Quote
#5
Thanks!
Quote
#6
I've got this mostly working, however there are few registry values that are raising a 'UnicodeEncodeError' error. I'm pretty sure this is because of the binary and hex values. What is the best way to convert these to strings? The other values convert from bytes to string without any issues.
Quote
#7
What are using and what is the code?
winreg Python 3 is what you should be using.

For Python 2 there where a winreg_unicode module.
Quote:The winreg_unicode package is a drop-in replacement for Python 2’s _winreg module.
However,it returns unicode values where possible, similar to Python 3’s winreg module.
Quote
#8
I'm using the 'regobj' module as suggested by Larz60+

The Python version I'm running is 3.6.1
Quote
#9
regobj there has been no update since 2011,
so i don't know if it handle Unicode as Python 3 do.
For Python 3.6 use winreg.
Quote
#10
I looked at the code, and it does check for Python 3.  If it finds it then it uses winreg.  However, it could be missing something.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Running linux command line apps... dbrdh 0 100 Jan-30-2020, 01:14 PM
Last Post: dbrdh
  TurtleWorld on MAC in Python 3.6 issues benniehanas 3 1,214 Jul-09-2018, 08:00 PM
Last Post: ichabod801
  Pip command issues in windows golmolbandar 1 887 Jun-12-2018, 07:58 PM
Last Post: snippsat
  Running serverless command in python nacheeket 1 1,143 Mar-18-2018, 08:00 PM
Last Post: Larz60+
  Subprocess Popen command issues. Rabster 1 2,617 Jul-03-2017, 10:31 AM
Last Post: DeaD_EyE
  Adding regedit value to glob.glob AlterBlitz 2 1,278 May-18-2017, 09:09 PM
Last Post: nilamo
  subprocess return of stdout after running Linux command ivanachukapawn 7 4,358 Oct-13-2016, 05:37 PM
Last Post: micseydel

Forum Jump:


Users browsing this thread: 1 Guest(s)