[python-win32] modify environment variable

Tim Roberts timr at probo.com
Mon Dec 10 19:49:39 CET 2007


le dahut wrote:
>
> A python program launched at user logon rewrites some registry keys such 
> as "HKCU\Software\Microsoft\Windows\Current Version\Explorer\User Shell 
> Folders\AppData" but explorer keeps using the old value.
>   

Right, because Explorer is already running by the time your app
launches.  You need to notify (or restart) Explorer of the change.

> How can I make windows reload the registry since the users have a 
> mandatory profile and the value can be different depending on the 
> machine they are connecting to or the group they are member of ?
>   

"The machine they are connecting to"?  What does that mean?  Windows
certainly supports the concept of a "roaming profile", where a given
user gets the same profile setup no matter what machine they are on. 
The domain controller sets that up by copying the profile files and
setting up the registry entries the first time they login on each
machine.  You can also use a domain login script to make these kinds of
changes.  Doing this stuff in a script called from the Startup group is
the wrong way to do it.

You should be able to use SHSetFolderPath to do this, but it isn't
exported by name.  You have to use GetProcAddress to fetch the address
by ordinal.  That's going to make it pretty hard to use from Python. An
alternative is to use the IKnownFolder interface, which has a SetPath
method to do this.  But again, I think you are trying to install a hack
solution for something that is fully supported by the normal Windows IT
infrastructure.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list