Where is the path information in DOS saved - dos

I had recently entered set path = c:\TC\bin;%path%. Thereafter entering path got this path = c:\tc\bin;BLAH-BLAH; and it worked. I closed command and reopened it does not work and on checking I get path=BLAH-BLAH; only. The recent addition I made was not present. Any clues? Thanks.

Environment variables are saved in a registry setting.
When you edit an environment variable in a command shell, the change only applies to that command shell (as you found).
If you want to set the path for the whole system you need to set it centrally - in Windows XP you can right click on "My Computer", choose "Properties", "Advanced" then click on "Environment Variables" at the bottom, and similar methods apply to other Windows sytems.
If you want to edit it programmatically you would need to do this through the registry APIs. There are answers about how to do this here: Programmatically modifiy environment variables?

Related

How do I add Ruby to the PATH variable on Windows?

I have Ruby installed, but I still need to add it to the PATH variable. I found something online for how to manually add it using the command line:
set PATH=C:\Ruby200-x64\bin;%PATH%
But before I try it, I want to be sure it's not going to overwrite what's currently in the PATH variable. (I have no experience with this stuff so I don't know what to expect).
Thanks in advance for your help!
first, notice that this question is not really about Ruby, rather about how to set a path in windows (it work the same way if you want to add an executable different from Ruby)
second, you are not overwriting the PATH environment variable because you add the existing content of the same to the new one you are setting in:
set PATH=C:\Ruby200-x64\bin;%PATH%
the %PATH% is the current content of the PATH variable.
Consider using
set PATH=%PATH%;C:\Ruby200-x64\bin
instead, this will make your OS search the original path before searching the ruby bin folder. Maybe it makes few difference on modern computers, but my old DOS days claim the second solution is better.
third and last point, in Windows you can set environment variables in control panel / system properties
How to get there depends on the version of your OS, but if you search for the ambient variables and system variables you should get there.
From the Desktop, right-click the very bottom left corner of the screen to get the Task Menu.
From the Task Menu, click System.
Click the Advanced System Settings link in the left column.
In the System Properties window, click on the Advanced tab, then click the Environment Variables button near the bottom of that tab.
In the Environment Variables window (pictured below), highlight the Path variable in the "System variables" section and click the Edit button.
Add or modify the path lines with the paths you want the computer to access. For ruby it will be:
;YOUR_RUBY_INSTALLATION_PATH\bin;
The operation with set PATH=C:\Ruby200-x64\bin;%PATH% is probably only temporary until you restart your computer.
I just wanted to let everyone know that when you install rubyinstaller on Windows and follow its steps, there is no option to 'add to path variables' because it automatically adds it.
Rubyinstaller trolled me hard because it said gem not found when I did gem install sass immediately after install.
Your path variable is probably already set if you used rubyinstaller.
The trick is to open CMD or I would imagine, PowerShell, ConEMU, etc, git bash, and type gem.
Press WINKEY and type cmd
Type gem install sass (or whatever else that is in the bin folder for Ruby)
I just went to add the PATH variable, and it was already set, so my problem was the garbage command line tool that opened after installing rubyinstaller.
You can also do these steps to add to the PATH variables:
Press WINKEY
Type view advanced system settings
Open that
Click Environment Variables
Click Path in the list
Click Edit
Check if C:\Ruby24-x64\bin is already there, if so, done
Click New and type in C:\Ruby24-x64\bin
Done
Yes, this is correct. In your example %PATH% will be expanded to the current value of the PATH variable, so this command is effectively adding a new entry to the beginning of the PATH.
Note that calling set PATH will only affect the current shell. If you want to make this change permanent for all shells, the simplest option is to set it as a user variable using the Environment Variables dialog box.
On Windows 8 you can open this dialog by hitting Win+s and searching for 'environment variables'. On earlier versions of Windows you can right-click 'My Computer', choose Properties, then Advanced system settings, then Environment variables. You can create (or update) a PATH variable in the user variables section and add whatever entries you need. These will be appended to the existing system path. If you take this approach you will need to open a new cmd shell after updating the variables.
Fear nothing, What you are doing is prepend C:\Ruby200-x64\bin to the existing %PATH%, this is what the command you posted does.
The path is a list of directories, separated by ;, in which the system will look for the command you execute.
In your case it's:
C:\Ruby200-x64\bin
%PATH%, if you print it on the command line, you'll find it's itself a list of directories separated by ;.
In case you want to make your change permanent, you have to change your PATH sytemwide.
For CLI, as noted elsewhere calling SET on the path variable only acts on the current window and closing it or restarting windows voids the change.
Example the transient Version selected as the answer:
set "PATH=%PATH%;C:\Ruby200-x64\bin"
To correctly set the path permanently in CLI use the path command:
PATH %PATH%;C:\Ruby200-x64\bin
This will persist between CMD windows and after reboots.
I know this is questions has the Windows tag, however it is one of the first DuckDuckGo results for "ruby gems add to path" so I just wanted to add this.
On Linux you can add this line to the end of your .bashrc in order to add it to your path:
export PATH=$PATH:~/.gem/ruby/2.6.0/bin

How to create a custom percent (%) shortcut like %appdata%?

Is it possible?
If so, how?
Can it be done in CMD?
Existing shortcuts examples :
%appdata%
%temp%
%userprofile%
These are environment variables and you can set your own, yes.
You can set them within a script or at cmd prompt with set, and you can make "global" environment variables by going to System Properties/Advanced and clicking the Environment Variables button. Variables added there will be available to all applications. If you have existing cmd windows open, though, they won't get the global variables - you will need to open new windows to make these variables available.
This should help someone
try %AppData%

How to setup MCR_CACHE_ROOT in Windows

I know this may be an easy question but How can I setup MCR_CACHE_ROOT in Windows? Can you provide me with the detailed steps. And where should I point the path to MCR_CACHE_ROOT to speed up my compiled application startup time?
For Windows 7, you set it as an environment variable as follows:
Click Start then right-click on Computer and choose Properties from the menu.
In the System window, click Advanced system settings in the left panel.
In the System properties dialog, select the Advanced tab and click the Environment variables button.
To add for all users, click New under the System variables window.
For Windows XP it's very similar and is described here.
Then you can enter MCR_CACHE_ROOT as the variable name, and the required path to variable value. Ok everything and it's done.
You can set the path wherever you like, but it's probably better to create a folder e.g. C:\MATLAB Cache and set it there.

Why can't I invoke python from the command line?

I have Python 2.6 installed on Windows Vista. If I am at C:\Python26> and I type python, Python's command-line interface starts, as desired.
I have added C:\Python26 to my PATH so that I would be able to run Python scripts from any directory, but it hasn't helped. In particular, from any other directory, the command python is not recognized.
I appreciate any guesses as to what change would get this working.
Edit: First, I have re-opened my cmd window (several times) so that is not the issue.
To clarify how I added C:\Python26 to the PATH, I clicked the following:
Computer -> System Properties -> Advanced system settings -> Environment Variables
at the point I select PATH and click Edit. I added C:\Python26 to the Variable Value field, separating this from the previous entries with a semicolon. Then I click OK a few times.
Edit #2 I've now checked my PATH by typing path at the command prompt. C:\Python26 is certainly in the path. I'll reboot anyway, and see if that helps.
This still sounds like a path issue.
If you have just added c:\Python26 to your path, then you need to open a new cmd window before those changes take effect, they won't apply to your existing cmd windows.
If you're unsure how to do this in Windows Vista, here is the instructions.
Select Settings -> Control Panel from the start menu.
Double click the 'System' icon.
Choose 'Advanced System Settings' on the left hand side.
Choose 'Environment Variables'
In the bottom list, select 'Path', and click 'Edit...'
At the end of the path string, add ;C:\Python26, leaving everything else the same, then click OK, then click OK again on the various windows still open.
Now open a new cmd window, and try the 'python' command from any directory - it should work.
This may be obvious to most people, but hopefully anyone with the same problem will find the help they need in this answer.
if you are certain that you have added the directory to the path, you may just need to open up a new command window for it to take the changes to the current path.
Double and triple check that you added the path correctly and didn't make a typo.
Restart your machine.
In the top panel where it says User Variables for YOUR NAME HERE,
select path, click the top edit button.
Append ";C:\Python26" without quotes at the end of the text in the "Variable Value" textbox.
That solved the problem for me.
Other options are to reinstall or to create a .bat file with c:\python26\python.exe and put that in your path

How to set user environment variables in Windows Server 2008 R2 as a normal user?

In older versions of Windows, it was just open the Control Panel, select the System applet, select the Advanced tab, and then hit the Environment variables button. As a normal user, you could edit the "User variables" but not the "System variables".
In Windows Server 2008 R2, if I try to hit the Advanced System settings option in the System applet, it prompts for the Administrator password.
You can also use this direct command line to open the Advanced System Properties:
sysdm.cpl
Then go to the Advanced Tab -> Environment Variables
OK I found it. Arg, an exercise in frustration. They left the old window menu traversal path for changing environment variables in there, but limited access to administrators only. As a normal user, if you want to change it, you need to go through a different set of options to arrive at the same frigging window.
Control Panel -> User Accounts -> User Accounts -> Change my environment variables.
Step by step instructions:
Go to Control Panel \System and Security\System
Click on Change Settings
Go to “Advance” tab
Click on Environment Variables
Under "Start" enter "environment" in the search field. That will list the option to change the system variables directly in the start menu.
This can be done from the command line using the SETX command. For example to 'move' your temporary files to another disk:
SETX TEMP d:\tmp
In command line prompt:
set __COMPAT_LAYER=RUNASINVOKER
SystemPropertiesAdvanced.exe
Now you can set user environment variables.
I created a godmode folder on the desktop. just create a new folder on the desktop and call it GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}
it will name the folder as godmode and populate the content with various config options, you can then just type in ENVIRO in the search to find the relevant config option, open it and it opens sysdm.cpl in the advanced tab, you can change the environment variables from there.
There are three ways
1) This runs the GUI editor for the user environment variables. It does exactly what the OP wanted to do and does not prompt for administrative credentials.
rundll32.exe sysdm.cpl,EditEnvironmentVariables
(bonus: This works on Windows Vista to Windows 10 for desktops and Windows Server 2008 through Server 2016. It does not work on Windows NT, 2000, XP, and 2003. However, on the older systems you can use sysdm.cpl without the ",EditEnvironmentVariables" parameter and then navigate to the Advanced tab and then Environment Variables button.)
2) Use the SETX command from the command prompt. This is like the set command but updates the environment that's stored in the registry. Unfortunately, SETX is not as easy to use as the built in SET command. There's no way to list the variables for example. Thus it's impossible to do something such as appending a folder to the user's PATH variable. While SET will display the variables you don't know which ones are user vs. system variables and the PATH that's shown is a combination of both.
3) Use regedit and navigate to HKEY_CURRENT_USER\Environment
Keep in mind that changes to the user's environment does not immediately propagate to all processes currently running for that user. You can see this in a command prompt where your changes will not be visible if you use SET. For example
rem Add a user environment variable named stackoverflow that's set to "test"
setx stackoverflow test
set st
This should show all variables whose names start with the letters "st". If there are none then it displays "Environment variable st not defined".
Exit the command prompt and start another. Try set st again
and you'll see
stackoverflow=test
To delete the stackoverflow variable use
setx stackoverflow ""
It will respond with "SUCCESS: Specified value was saved." which looks strange given you want to delete the variable. However, if you start a new command prompt then set st will show that there are no variables starting with the letters "st"
(correction - I discovered that setx stackoverflow "" did not delete the variable. It's in the registry as an empty string. The SET command though interprets it as though there is no variable. if not defined stackoverflow echo Not defined says it's not defined.)

Resources