Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 677
user366203 Avatar asked Jun 14 '10 10:06

user366203


People also ask

How do I create an environment variable shortcut?

Environment Variables Shortcut To have a quick access you can create a shortcut to the environment variables editor. Right click on the empty space of your desktop and select New -> Shortcut from the context menu. Set “Environment Variables” as the name of the shortcut and click on Finish .

How do I set an environment variable in an application?

On the Advanced tab, click Environment Variables. Click New to create a new environment variable. Click Edit to modify an existing environment variable. After creating or modifying the environment variable, click Apply and then OK to have the change take effect.

How do I set multiple environment variables in Windows?

Press the Windows key + X to access the Power User Task Menu. In the Power User Task Menu, select the System option. Click the Advanced System Settings link in the left column. In the System Properties window, click the Advanced tab, then click the Environment Variables button near the bottom of that tab.


2 Answers

As explained here: http://www.labs64.com/blog/2012/06/set-environment-variables-in-windows-shortcut/ you can do it without a bat file too.

Set Target to e.g.:

C:\Windows\System32\cmd.exe /c "SET path=%path%&& START /D ^"C:\Program Files (x86)\Notepad++^" notepad++.exe" 

To avoid see the command prompt for a split second before it close again, you should set

Run: Minimized  

on the Shortcut tab

(Tested on Windows 7, Windows 10)

like image 97
Jens Avatar answered Sep 20 '22 03:09

Jens


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" 
like image 20
GvS Avatar answered Sep 20 '22 03:09

GvS