Created
April 13, 2024 11:00
-
-
Save 1208nn/63758451e4feb88833433b75a7cf2145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import winreg | |
from os import getcwd | |
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Environment", 0, winreg.KEY_READ | winreg.KEY_WRITE) | |
path, _ = winreg.QueryValueEx(key, "Path") | |
if "%N0ENV%" not in path: | |
path += ";%N0ENV%" | |
path=path.replace(';;',';') | |
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, path) | |
try: | |
path, _ = winreg.QueryValueEx(key, "N0ENV") | |
if getcwd() not in path: | |
path += f";{getcwd()}" | |
winreg.SetValueEx(key, "N0ENV", 0, winreg.REG_EXPAND_SZ, path) | |
except FileNotFoundError: | |
winreg.SetValueEx(key, "N0ENV", 0, winreg.REG_EXPAND_SZ, getcwd()) | |
winreg.CloseKey(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment