Programmatically modifiy environment variables?

前端 未结 6 500
盖世英雄少女心
盖世英雄少女心 2020-12-05 05:37
  • Windows 7.
  • It\'s for my own machine, so it doesn\'t matter if it requires admin rights or something.
  • Preferably in Python or .NET, but I can learn a
6条回答
  •  独厮守ぢ
    2020-12-05 06:05

    or you could try a Windows PowerShell script; PowerShell is installed on Windows 7 by default.

    run powershell.exe

    PS C:\> [Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")
    

    Then, for example, from cmd.exe

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\>echo %TestVariable%
    Test value.
    
    C:\>
    

    Or (in a new) powershell.exe

    PS C:\> echo $ENV:TestVariable
    Test Value.
    PS C:\>
    

    check out http://technet.microsoft.com/en-us/library/ff730964.aspx

提交回复
热议问题