By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Reading registry export files

P: n/a
Hi,

I have exported some registry-keys using Regedit to a number of
..reg-files. I can open these files using any text editor. Now I wanted
to write a simple Python script to concatenate all these files to one
output file. (Please note that I'm a newbie).

However, if I do something like:
f=open('c:/documents and settings/myname/desktop/test.reg','r')
r=f.read()
print r


I get a lot of garbage with a lot characters which the Python shell
cannot display (it display a square instead). The above code does work
with ordinary text files.

Should I open these reg-files in a different way, or treat them
differently once read in Python?

Thanks for any help.

Kind regards, George
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
It works fine for me on NT. I think it has nothing to do with Python
but with the way the file is created - what windows version are you on?
Also note the possibility the '/' - I prefer a noatation like below to
avoid ambiguity.

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
py> f = open(r"d:\test.reg")
py> r = f.read()
py> print r
REGEDIT4

I would do it like this however, then join all lists from various .reg
files:
py> f = open(r'd:\test.reg')
py> r = f.readlines()
py> print r
['REGEDIT4\n', '\n',
'[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Ole]\n', '"Enabl
eDCOM"="Y"\n',
'"DefaultLaunchPermission"=hex:01,00,04,80,64,00,0 0,00,80,00,00,0
0,00,00,00,00,\\\n', '
14,00,00,00,02,00,50,00,03,00,00,00,00,00,18,00,01 ,00,00
,00,01,01,00,00,00,\\\n', '
00,00,05,12,00,00,00,00,00,00,00,00,00,18,00,01,00 ,
00,00,01,01,00,00,00,00,\\\n', '
00,05,04,00,00,00,00,00,00,00,00,00,18,00,01,0
0,00,00,01,02,00,00,00,00,00,\\\n', '
05,20,00,00,00,20,02,00,00,01,05,00,00,00
,00,00,05,15,00,00,00,a0,5f,84,1f,\\\n', '
5e,2e,6b,49,ce,12,03,03,f4,01,00,00,
01,05,00,00,00,00,00,05,15,00,00,00,a0,\\\n', '
5f,84,1f,5e,2e,6b,49,ce,12,03,0
3,f4,01,00,00\n', '\n']


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Ole]
"EnableDCOM"="Y"
"DefaultLaunchPermission"=hex:01,00,04,80,64,00,00 ,00,80,00,00,00,00,00,00,00,

14,00,00,00,02,00,50,00,03,00,00,00,00,00,18,00,01 ,00,00,00,01,01,00,00,00,\

00,00,05,12,00,00,00,00,00,00,00,00,00,18,00,01,00 ,00,00,01,01,00,00,00,00,\

00,05,04,00,00,00,00,00,00,00,00,00,18,00,01,00,00 ,00,01,02,00,00,00,00,00,\

05,20,00,00,00,20,02,00,00,01,05,00,00,00,00,00,05 ,15,00,00,00,a0,5f,84,1f,\

5e,2e,6b,49,ce,12,03,03,f4,01,00,00,01,05,00,00,00 ,00,00,05,15,00,00,00,a0,\
5f,84,1f,5e,2e,6b,49,ce,12,03,03,f4,01,00,00

Jul 19 '05 #2

P: n/a
It works fine for me on NT. I think it has nothing to do with Python
but with the way the file is created - what windows version are you on?
Also note the possibility the '/' - I prefer a noatation like below to
avoid ambiguity.

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
py> f = open(r"d:\test.reg")
py> r = f.read()
py> print r
REGEDIT4

I would do it like this however, then join all lists from various .reg
files:
py> f = open(r'd:\test.reg')
py> r = f.readlines()
py> print r
['REGEDIT4\n', '\n',
'[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Ole]\n', '"Enabl
eDCOM"="Y"\n',
'"DefaultLaunchPermission"=hex:01,00,04,80,64,00,0 0,00,80,00,00,0
0,00,00,00,00,\\\n', '
14,00,00,00,02,00,50,00,03,00,00,00,00,00,18,00,01 ,00,00
,00,01,01,00,00,00,\\\n', '
00,00,05,12,00,00,00,00,00,00,00,00,00,18,00,01,00 ,
00,00,01,01,00,00,00,00,\\\n', '
00,05,04,00,00,00,00,00,00,00,00,00,18,00,01,0
0,00,00,01,02,00,00,00,00,00,\\\n', '
05,20,00,00,00,20,02,00,00,01,05,00,00,00
,00,00,05,15,00,00,00,a0,5f,84,1f,\\\n', '
5e,2e,6b,49,ce,12,03,03,f4,01,00,00,
01,05,00,00,00,00,00,05,15,00,00,00,a0,\\\n', '
5f,84,1f,5e,2e,6b,49,ce,12,03,0
3,f4,01,00,00\n', '\n']


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Ole]
"EnableDCOM"="Y"
"DefaultLaunchPermission"=hex:01,00,04,80,64,00,00 ,00,80,00,00,00,00,00,00,00,

14,00,00,00,02,00,50,00,03,00,00,00,00,00,18,00,01 ,00,00,00,01,01,00,00,00,\

00,00,05,12,00,00,00,00,00,00,00,00,00,18,00,01,00 ,00,00,01,01,00,00,00,00,\

00,05,04,00,00,00,00,00,00,00,00,00,18,00,01,00,00 ,00,01,02,00,00,00,00,00,\

05,20,00,00,00,20,02,00,00,01,05,00,00,00,00,00,05 ,15,00,00,00,a0,5f,84,1f,\

5e,2e,6b,49,ce,12,03,03,f4,01,00,00,01,05,00,00,00 ,00,00,05,15,00,00,00,a0,\
5f,84,1f,5e,2e,6b,49,ce,12,03,03,f4,01,00,00

Jul 19 '05 #3

P: n/a
* wi******@hotmail.com (2005-06-22 13:59 +0100)
It works fine for me on NT. I think it has nothing to do with Python
but with the way the file is created - what windows version are you on?


Windows uses UTF-16 since Windows 2000. Regedit offers the possibility
to export in the old Win9x/NT4 format.
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.