_winreg and accessing registry settings of another user
Tim Golden
mail at timgolden.me.uk
Fri Mar 5 04:59:17 EST 2010
On 05/03/2010 07:21, News123 wrote:
> My script shall be part of installing and configuring a PC with some
> default settings with the minimal amount of human administrator
> interactions.
>
> The steps:
> - install windows
> - install python
> - setup one admin account and one or more user accounts (without admin
> privileges)
> - run a script, that preconfigures registry settings for some users.
> 2.) being able to load the 'hive' of another user into the registry and
> be therefore able to change his settings. I didn't find a function
> allowing _winreg to load additional 'hives'
You can use a combination of the win32security, win32api and win32profile
modules from the pywin32 package for this:
<code>
import win32security
import win32api
import win32profile
username = "USERNAME"
domain = "DOMAIN"
password = "PASSWORD"
hUser = win32security.LogonUser (
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT
)
hReg = win32profile.LoadUserProfile (
hUser,
{"UserName" : "fozrestore"}
)
try:
print win32api.RegEnumKeyExW (hReg)
finally:
win32profile.UnloadUserProfile (hUser, hReg)
</code>
TJG
More information about the Python-list
mailing list