Search code examples
windowsenvironment-variablesshortcut

Can I set an environment variable for an application using a shortcut in Windows?


I have a feeling I should be able add a directory to the PATH environment variable on an application-lifetime basis, but I can't find out how to do this. Is it possible to add a parameter to a Windows shortcut that appends a directory to the current value of PATH for use by the application being linked?


Solution

  • Let the shortcut execute a batch file (.cmd), that

    • Sets the environment variable
    • execute the app
    • You use "START" to execute the app, this will start the app in another process, but it will copy the environment. You do not wait for the app to finish.
    • Now you can exit the batch file.

    Should look like this:

    @echo off
    set path=%path%;C:\My Folder
    start "Window Title" "Path to my exe"