473,387 Members | 1,476 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Reading Windows (NT/2000/XP) system and user environment variables

What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

Thanks for the help!

jep

Jul 18 '05 #1
3 5607
Jim Potts wrote:
What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

Thanks for the help!

jep

first install Mark Hammond's excellent Win32all extensions:
http://starship.python.net/crew/mhammond/

Then it's really simple:
import win32api
win32api.GetEnvironmentVariable('path')

'c:\\bin;c:\\Python23\\scripts;C:\\WINDOWS\\system 32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\PRO GRA~1\\COMMON~1\\Ulead
Systems\\MPEG;C:\\Program Files\\Common Files\\Ulead Systems\\MPEG'

Jul 18 '05 #2
<quote name="Jim Potts" date="1065120522" email="ji*******@sbcglobal.net">
What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

</quote>

import os
os.environ

See also the documention on the os module.

Gerrit.

--
Mozilla _is_ the web: it grows faster than you can download it.
1011001 1101111 1110101 1110010 1110011 0101100
1000111 1100101 1110010 1110010 1101001 1110100

Jul 18 '05 #3
If you need to get the list of system environment variables and the (separate) list of user environment variables, you'll have to read the following registry settings:

System: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Session Manager\Environment

User: HKEY_CURRENT_USER\Environment

You can use the win32api functions RegConnectRegistry, RegOpenKey, RegQueryValue etc. for these.

Felix.
What is the best way in Python version 2.x to read/get Windows (nt/2000/xp)
system and user environment variables?

Thanks for the help!

jep

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eugene | last post by:
I am trying to use db2batch from my XP client against a remote database. And here's what I am getting: C:\work\Tuning\DB2\db2batch> db2batch -d oakl0 -a fs/fs -f db2batch.sql Running in...
3
by: Steven Fox | last post by:
============================================================ About DB2 Administration Tools Environment ============================================================ DB2 administration tools level:...
4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
4
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code...
5
by: Andrew | last post by:
Hey all, Requesting help from the VB.Net gurus in here. I was given a task to write a Windows Service (VB.Net) that would run an external program, and if that program closed for any reason...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
6
by: Fuzzyman | last post by:
Hello all, I would like to set a Windows Environment variable for another (non-child) process. This means that the following *doesn't* work : :: os.environ = value In the ``win32api``...
2
by: Ran Raj | last post by:
In Windows environment, I want to create/update both system and user environment variables. By default, I can access/modify the variables using Start > Control panel > System > Advanced >...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.