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

Discussion in 'Python' started by Jim Potts, Oct 2, 2003.

  1. Jim Potts

    Jim Potts Guest

    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
     
    Jim Potts, Oct 2, 2003
    #1
    1. Advertising

  2. Jim Potts

    Gerrit Holl Guest

    <quote name="Jim Potts" date="1065120522" email="">
    > 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
     
    Gerrit Holl, Oct 2, 2003
    #2
    1. Advertising

  3. 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\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\PROGRA~1\\COMMON~1\\Ulead
    Systems\\MPEG;C:\\Program Files\\Common Files\\Ulead Systems\\MPEG'
     
    Rudy Schockaert, Oct 2, 2003
    #3
  4. 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\Control\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
     
    Felix McAllister, Oct 3, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Z2F1cmF2?=

    Uploading Data From MS Acess 2000 ti SQL server 2000

    =?Utf-8?B?Z2F1cmF2?=, Jan 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    829
    Mary Chipman [MSFT]
    Jan 9, 2006
  2. Guest
    Replies:
    2
    Views:
    910
    dave wanta
    Jul 11, 2003
  3. Replies:
    6
    Views:
    275
    Steve Callaway
    Jul 19, 2005
  4. Replies:
    1
    Views:
    117
    Bart Lateur
    Mar 18, 2007
  5. Thierry
    Replies:
    2
    Views:
    160
    sisyphus
    Jun 28, 2008
Loading...

Share This Page