[python-win32] Vista, _winreg and "Access denied"

Mark Hammond mhammond at skippinet.com.au
Tue May 27 16:02:15 CEST 2008

> With Vista (XP works fine), when using SetValueEx in a script ran by an
> administrator I get "Access Denied". I know that's it's due to UAC so
> does someone know how to do a 'sudo' when using something else than
> CreateProcess ?

The short version of my understanding of Vista and UAC:  Firstly, an
existing process can not be elevated - once you are running, you are out of
luck - your option is, basically, re-execute yourself requesting elevation
and have the new process retry the operation (the exception is when you are
using a COM object - in which case you can ask for an "elevated" COM object
- but that is rare, so I'm treating it as the exception :)  If you want to
reexecute yourself, IIUC you are limited to calling ShellExecute(Ex), with
the "verb" set to "runas" - which can be a PITA, but I'm not aware of other
options.  My current best guess for when you might *need* to do this if is
win32com.shell.IsUserAnAdmin() returns true (which needs pywin32-211, which
I promise is in the process of being tested right now :)

As Tim said though, please read MSDN and all other references you can find,
and please correct me if I'm wrong/mistaken/confused/etc for everyone elses



More information about the python-win32 mailing list