Basically, it is a wrapper around the Windows API. This way it should be used as Windows OS says it should be used. If you have (say) a C++ code, you can easily rewrite it to Python. Fortunately, the resulting code is much more brief. Of course, you can write your own function that takes arguments as you need, and then it calls the _winreg functions.

See the sample below that reads the MDAC version from the registry. It prints the following on my computer:

Thanks for the response. I am trying to have this script read the registry and scan the keys and print them. I need the script to read and cycle though several values, each are numbered like url1, url2 etc.

Do you know where the values are located? If yes, you can get more details about the key via the _winreg.QueryInfoKey() and access the values from inside via EnumValue(). See the snippet below. It prints the following info on my computer (long url values shortened for brevity here):

That works, thanks. But how do I get the data when there are several user profiles on the box? How can I make the script run through and list the data for each user? As far as the code above can you explain how it works? I am trying to learn Python. Thanks for your great help!

Well, the work with the registry is Windows specific and it is rather heavy handed with respect to how it could be implemented in Python. The Windows Registry consists of several trees. Their roots are named with the well known identifiers (like HKEY_CURRENT_USER). That tree identification is passed to OpenKey() as the first argument. The HKEY_CURRENT_USER points to one of the subtrees of the tree HKEY_USERS. This way, you want to process the users from inside that tree. See http://technet.microsoft.com/en-us/library/cc976337.aspx for details. The users are assigned so called Security ID that represents them. When displayed as a string they look like "S-1-5-21-1000062535-2000000004-1488888878-1554". If you find shorter SID's, they are probably related to system parts that may behave as users sometimes.

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

OK. Let's do it in steps. Firstly, here is the modification (also function name changed). Run the regedit.exe, unfold the HKEY_USERS and copy your SID to the argument of the function call below. It should do the same thing that the above script for HKEY_CURRENT_USER. Notice how the key in the registry is written in a string. The earlier

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs

can be written in my case also as (there are decimal numerals instead of the x'es below)

From that point of view, you can pass the SID (S-1-5-21-1xxxxxxxx5-2xxxxxxxx4-1xxxxxxxx8-1154) to the function and concatenate it with the '\Software\Microsoft\Internet Explorer\TypedURLs'. The HKEY_USERS is a kind of concatenaded by the .OpenKey() method.

Now the code that searches the URLs in all subkeys of the HKEY_USERS. Not all subkeys are related to the users. This means that they probably do not contain the urls. The code below solves that via capturing the exception and throwing another.

The code below introduces also what is called a "generator function" in Python. The function can be used for example in for loops and its usage behaves as generator of a sequence (each time one item). The yield command instead of the return command is used inside the body of the function.

See below. The userSIDs() actually does not return only the user's SIDs. It returns also the other subkeys -- it is basically the same as the code in the upper example. The difference is that it uses the yield instead of the print command. Then it can be called in the for loop as here:

for sid in userSIDs():
print sid

The theUserSID_IETypedURLs() was also modified to get the earlier behaviour. Study the code and ask what are you interested in.

import _winregdef theUserSID_IETypedURLs(sid): # Open the IE typed URLs for the sid and return the handle object. The list # of the URLs may not be present. Try it and throw the StopIteration early # if no URL is there. try: hKey = _winreg.OpenKey(_winreg.HKEY_USERS, sid + r'\Software\Microsoft\Internet Explorer\TypedURLs') except: raise StopIteration # Get the information about the key. subkeyCnt, valuesCnt, modtime = _winreg.QueryInfoKey(hKey) print subkeyCnt, valuesCnt # Retrieve the value tuples (name, value, type). for n in xrange(valuesCnt): yield _winreg.EnumValue(hKey, n)[1] # yield the url's only # Close the handle object. _winreg.CloseKey(hKey)def userSIDs(): # this generator function should be enhanced hKey = _winreg.OpenKey(_winreg.HKEY_USERS, '') subkeyCnt, valuesCnt, modtime = _winreg.QueryInfoKey(hKey) # Generate the subkeys. for n in xrange(subkeyCnt): yield _winreg.EnumKey(hKey, n) # notice the yield instead of return _winreg.CloseKey(hKey)for sid in userSIDs(): # here the generator is used to get the SIDs print sid for url in theUserSID_IETypedURLs(sid): print ' ', url

That works great! Thank you. I am learning alot via this exercise! Is there a way to covert the sid to the actual user name and what type of account it is (admin or regular user, local group membership etc)?

What books would you recommend I use to get really good at Python, I really enjoy it.

This is less Python related and more MS Windows related. I am not very good in it. However, you should probably use the so called pywin32 extension (http://sourceforge.net/projects/pywin32/) by Mark Hammond (http://sourceforge.net/users/mhammond). Then you should use the win32security module from that package. If I recall correctly, the pywin32 was available as compiled binary installation earlier. However, the sourceforge contains only the sources and you need to compile it using the MS Visual C++ (probably some free version will be sufficient -- I did not dig into details). Or you may find the package precompiled elsewhere. After successfull installation, try the following snippet:

You can see here that not every SID is related to a user. I did not play further with that. Also, you should probably get the users' SIDs from somewhere else. The example here is rather dirty and uses mostly the trial/failure of various SIDs from HKEY_USERS. The official documentation says that you should search for SIDs in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList (see http://support.microsoft.com/kb/154599/EN-US/).

Installing Python 2.7.3 version on Windows operating system
For installing Python first we need to download Python's latest version from URL" www.python.org "
You can also get information on Python scripting language from the above mentioned we…

Learn the basics of lists in Python.
Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…

Learn the basics of while and for loops in Python.
while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows: while <condition>: do something repeate: The break statement m…