[python-win32] modify environment variable

le dahut le.dahut at laposte.net
Tue Dec 11 14:39:32 CET 2007


Actually I use winlogon notification 
http://www.codeproject.com/KB/system/winlogon_notification_package.aspx
to launch an app that reads a configuration file on a samba PDC server 
and write some registry keys.
The configuration file depends on :
- user name or group
- machine name (there's a concept of machine group based on machine names)

thus configuration file can be 
\\<pdc>\netlogon\<machine_group>\<user_name_or_grp>.xml

With graphical app that contains a database of registry keys and 
descriptions about them ("User cannot access printer configuration", 
"Hide checked drivers from My Computer" etc.).

So at logon, the program rewrites also the Desktop, Start Menu, ... and 
AppData paths. This is done before explorer starts (eventually kill and 
restart it if it runs). But in a command line prompt "cmd" 'echo 
%appdata%' doesn't return the path written in the registry. And I've 
noticed that some application gets AppdData path from something like 
"os.environ['APPDATA']".

What can I do to solve this ?

Tim Roberts wrote :
> 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.
> 


More information about the python-win32 mailing list