10.14.2013

Add programs Environment Variable

Add programs Environment Variable

Open up a command line interface by typing "cmd" enter (without the quotes) in the start menu search box or Windows Key+R. Next, in the command line just type:
PATH=%PATH%;c:\path\to\your\app.exe [enter]

That's it. To confirm that your Path has been updated, just type:
echo %PATH% [enter]
and check if your new path is there. Next type the name of your app under any path and you should have it running.

For example to add the STSADM for SharePoint Administration tool so that it is easily accessible type the following command...

SET PATH =%PATH%;C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN

Confirm that the path has now been appended to the environment variable %PATH%

echo %PATH%

Type stsadm.exe /? under any directory and the executable will list the available options. 

In short:
 
setx /M PATH "%PATH%;<your-new-path>"

*Running cmd as administrator.
The /M option sets the variable at SYSTEM scope. The default behaviour is to set it for the USER.
The truncation issue happens because when you echo %PATH% it will show the concatenation of SYSTEM and USER values. So when you add it in your second argument to setx, it will be fitting SYSTEM and USER values inside the USER var. When you echo again, things will be doubled.
Additionally, the /M option requires administrator privilege, so you need to open your terminal with "run as administrator", otherwise setx will complain with "access to registry path is denied".
Last thing to note: You won't see the new value when you echo %PATH% just after setting it this way, you need to close cmd and open again.
If you want to check the actual values stored in registry...

User Variables
HKEY_CURRENT_USER\Environment
System Variables
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.