0

I'm working on a project which adds a certain directory to the Windows Path Environment variable. But I can't figure out how to add a directory to Path using Python

3

1 Answer 1

0

You will need to make sure to run this as an account with Admin privileges

import win32com.shell.shell as shell

def addPathToEnv(pathToAdd):
    """
    Add the supplied path the Windows Path Environment variable
    :param pathToAdd: <str> Full path to be added as Path Environment.
    """
    
    commands = f'setx /M PATH "%PATH%;{pathToAdd}"'
    shell.ShellExecuteEx(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c '+commands)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.