Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a path to windows path environment

Status
Not open for further replies.

yannb

Technical User
Mar 12, 2003
3
US
Hello,

I have a script which updates a bunch of windows machines with some new software. If the software has never been installed on those machines before, I need to add the path to that software into the windows path environment variable permanently.

here's what I do.

newpath = 'c:\\newapp'
path = os.environ['path']
path_array = path.split(';')
pathfound = 'false'
for p in path_array:
if p == newpath:
pathfound = 'true'
break
if pathfound == 'false':
os.environ[path] += ';' + newpath
print os.environ['path']

the last statement shows the new path was added to the path environment variable, however, when I right click on my computer, choose properties, environment, the new path did not get appended.

am I doing something wrong or is that just not possible

thanks

yann

 
Each time a new process starts, it inherits its environnement from the application which started it.

Thus your Python script inherits the environement of the system.
But altering it (by manipulating os.environ) will only alter its local copy of the system environement, not the system environment itself.

You will probably have to tweak the windows's registry for this (using the win32all modules).
For example, under my Windows NT 4 sp2, system environment variables are stored in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top