Environment Variables - How to

Discussion in 'Server Migration' started by Sarah Tanembaum, Jun 25, 2004.

  1. I'm wondering if there are such a command line/console version of setting
    the environment variables.

    Instead of using the GUI version, I'm used to create user using the console
    command, e.g:

    net user ...
    net user localgroup ...

    It is faster and I can use a .bat for automation.

    Now, I need to set up environment variables for all users in the systems.
    I'm using the control-panel -> system ->advanced -> environment variables to
    set up all the environment variables. How can I do that using the console
    windows(as administrator)?

    Thanks
     
    Sarah Tanembaum, Jun 25, 2004
    #1
    1. Advertisements

  2. Sarah Tanembaum

    Peter Guest

    use the SET command
    set myvar=fred
    echo %myvar%
     
    Peter, Jun 25, 2004
    #2
    1. Advertisements

  3. I know about setting it up for the current console, but I need to set up for
    all users and permanent as well.

    I know that you can do the above for the current windows, or use the login
    script to set that up, but I'm sure there are another where, I think, you
    have to write it to the registry so it will apply for all user.

    Thanks
     
    Sarah Tanembaum, Jun 25, 2004
    #3
  4. Perhaps any one can shed me some lights ---

    when I did Control Panel -> System ->Advanced -> Environment Variables and
    set some environment variables, where did it get written to? and how do one
    do it using the command line/console? Thanks
     
    Sarah Tanembaum, Jun 25, 2004
    #4
  5. Hi

    You can e.g use setx.exe for this.

    For WinXP yo it is included as a utility in the support tools installation
    package (on your WinXP CD) installed by suptools.msi.

    It is also in the free part of Win2000 Resource Kit:
    http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/setx-o.asp

    I would think you can use either version on either OS version.


    When adding or removing components from the _path_ from the command line,
    I suggest using Pathman.exe (Path Manager).

    Pathman.exe can be downloaded from here:
    http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/pathman-o.asp

    It will e.g. handle repeated entries.

    Pathman.exe is also in the Windows Server 2003 Resource Kit Tools
    http://www.microsoft.com/downloads/...69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en

    (The kit will install on WinXP or later)
     
    Torgeir Bakken \(MVP\), Jun 25, 2004
    #5

  6. Thanks I will check it out, but in the mean time, I found this under:

    HKLM\Current ControlSet\Control\Session Manager\Environment\
    ....
    ....

    And it contains all the path I created plus some that I'm not quite
    understand.
    It has some hex number for certain Environment Variables. Any idea?

    Can I just export the above and reload into different machine that has
    similar setup? Thanks
     
    Sarah Tanembaum, Jun 26, 2004
    #6
  7. Sarah Tanembaum

    Dave Patrick Guest

    Note that system environment variables are stored in;
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

    User environment variables are stored in;
    HKCU\Environment

    Also note the type is Reg_Expand_Sz which must be created with regedt32.exe
    Yes you can export and then import the *.reg file through regedit.exe but be
    careful with system variables.

    --
    Regards,

    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    http://www.microsoft.com/protect


    :
    | Thanks I will check it out, but in the mean time, I found this under:
    |
    | HKLM\Current ControlSet\Control\Session Manager\Environment\
    | ...
    | ...
    |
    | And it contains all the path I created plus some that I'm not quite
    | understand.
    | It has some hex number for certain Environment Variables. Any idea?
    |
    | Can I just export the above and reload into different machine that has
    | similar setup? Thanks
    |
    |
     
    Dave Patrick, Jun 26, 2004
    #7
  8. Thanks Dave. What is that hex number represent? Is it the ascii number?
    Thanks
     
    Sarah Tanembaum, Jun 26, 2004
    #8
  9. Sarah Tanembaum

    Dave Patrick Guest

    You're probably looking at them through regedit hence the hex value for a
    type Reg_Expand_Sz element. Try looking at them with regedt32.exe

    --
    Regards,

    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    http://www.microsoft.com/protect


    :
    | Thanks Dave. What is that hex number represent? Is it the ascii number?
    | Thanks
     
    Dave Patrick, Jun 26, 2004
    #9
  10. Dave,
    under regedt32, it display okay without the hex, but when I
    exported the Environment registry and read the text file, some values are in
    hex number. Any ideas?

    Thanks
     
    Sarah Tanembaum, Jun 26, 2004
    #10
  11. Sarah Tanembaum

    Dave Patrick Guest

    Yes, don't worry about it. You can't read them with a text editor.

    --
    Regards,

    Dave Patrick ....Please no email replies - reply in newsgroup.
    Microsoft Certified Professional
    Microsoft MVP [Windows]
    http://www.microsoft.com/protect


    :
    | Dave,
    | under regedt32, it display okay without the hex, but when I
    | exported the Environment registry and read the text file, some values are
    in
    | hex number. Any ideas?
    |
    | Thanks
     
    Dave Patrick, Jun 26, 2004
    #11
  12. Hi Sarah ,

    Thanks for your posting here.

    In Winnt/2000/xp, you can modify the registry directly.

    Please refer to the following document.

    104011 HOWTO: Propagate Environment Variables to the System
    http://support.microsoft.com/?id=104011

    Have a nice day!

    Regards,
    Bob Qin
    Product Support Services
    Microsoft Corporation

    Get Secure! - www.microsoft.com/security

    ====================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ====================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Bob Qin [MSFT], Jun 28, 2004
    #12
  13. Thanks.
     
    Sarah Tanembaum, Jun 28, 2004
    #13
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.