Re: SYSTEM and USER environment (was Your confirmation is requiredto join the Python-list mailing li

Discussion in 'Python' started by Dave Angel, May 4, 2009.

  1. Dave Angel

    Dave Angel Guest

    Allan Yuan wrote:
    > Hi,
    > I just wanna know how to set SYSTEM variables and USER variables of windows,
    > but got no way.
    > Firstly I thought "os.environ + os.system" may work well, but found no way
    > to let "os.environ" run to retrive USER variables.
    > Then I tried win32api, finding the GetEnvironmentVariables() mixing SYSTEM
    > and USER variables up, and SetEnvironmentVariables() failing to add
    > variables.
    > Could you help me, please?
    > Thanks a lot.

    First, you need to put a meaningful subject line on a query to the
    list. Hopefully you also did the confirmation, so that you'll actually
    be getting the list emails.

    Next, your problem. SYSTEM and USER variables are a uniquely Windows
    concept, and as far as I know, have no direct counterpart in Python.
    These are really just names used in the Control Panel applet to refer to
    two sections of the registry which are used to define which environment
    variables a task will start with, if the task is started directly from
    Explorer. Tasks that are started by other tasks (eg. the command line)
    get environment variables as defined by the parent.

    So, there are at least three obvious ways a process gets started. One
    is by explorer, in which case it gets the environment described above.
    Two is by a DOS box, in which case it gets the environment variables
    according to the rules of the CMD shell. And third is from an arbitrary
    3rd party process, in which case it's up to that developer.

    So, which are you trying to change? I'm suspecting you're interested in
    the Explorer version, for example that launches a program from a
    shortcut on the desktop, or via an association with a particular file
    extension. i don't know which registry variables are involved, but
    there are two registry keys,
    Try: hklm/SYSTEm/CurrentControlSet/Control/Session
    Manager/Environment for the SYSTEM environment variables
    and hkcu/Environment for the USER environment variables

    Experiment first with REGEDIT, then when you get the behavior you want,
    look up module _winreg (or winreg in Python 3.0) to do it
    programmatically. Notice that existing DOS boxes won't see these new
    variables, only things launched by Explorer or the equivalent.

    It's also possible you just want to set environment variables for a
    particular DOS box session. In that case, use a .BAT or .CMD file, in
    which a SET statement tells the shell what values to use next time it
    Dave Angel, May 4, 2009
    1. Advertisements

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. wopronet-subscribe-conf-1080784105.hgkjbmmdhhngpkh

    [wopronet] Your confirmation is needed to join the Group

    wopronet-subscribe-conf-1080784105.hgkjbmmdhhngpkh, Apr 1, 2004, in forum: Python
    Apr 1, 2004
  2. Replies:
  3. googleboy
    Benji York
    Oct 1, 2005
  4. techwr-l-confirm+22d099e2f3d881b010eaeb38c05837f62

    Your confirmation is required to join the TECHWR-L mailing list

    techwr-l-confirm+22d099e2f3d881b010eaeb38c05837f62, Sep 18, 2007, in forum: Python
    Sep 18, 2007
  5. Gerald Bauer

Share This Page