How to persistently set a variable in Windows 7 from a batch file?

前端 未结 7 1190
無奈伤痛
無奈伤痛 2020-12-02 08:38

I am trying to set the PATH environment variable in windows 7 using a bat-file; however it does not seem to work.

I am using this windows command:

se         


        
7条回答
  •  青春惊慌失措
    2020-12-02 09:26

    To do this properly I think you really need to go beyond a simple batch file. The MSDN documentation states:

    To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.

    First of all you won't be able to write to that key without a UAC elevation prompt. That's best arranged by adding the appropriate manifest to an executable file. Secondly, broadcasting WM_SETTINGCHANGE isn't simple from a batch file.

    In your position I'd write a short and simple console app to do the job.

提交回复
热议问题