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

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%

Related

Windows custom system variables in save/open boxes

For many years I've been using the windows custom system path to mapping folders and files to be accessible through RUN box. I put the main folder path in the PATH field of Environment Vars and so I can type the subfolder name in the RUN and access it.
Environment Vars:
Per example, I can type "cronos" in the RUN box and access a folder with this name, within "b:\wampp\www". I would like to use these variables in the Windows Explorer, on save / open boxes, in the same way that the %USERPROFILE% and %PATH% variables are used. I think that %cronos% should work, but it is not recognized.
var on save box:
Has anyone used the vars in this way? Any idea? Thanks.
To use it in this way, you need add "cronos" full path to Path variable in your system, and to do the same with all vars that you want.

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

Where is the path information in DOS saved

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?

View environment variable of process on Windows

How do I view the environment variable of a Windows process? Looking for Windows equivalent for something like environ file in procfs on Unix.
Process Explorer or one of its friends should help.
Check out GetEnvironmentStrings.
As ziya suggests, you can use the SysInternal's Process Explorer or, for example, slighly more feature rich Process Hacker.
Even though it's really trivial, I'll describe how to find the environment variables used by a specific process in any of those two applications:
in the list of running processes, select the process you're interested in (in Process Hacker or Process Explorer 16.40 and newer, you can use the search box on the main toolbar)
open the process' Properties dialog (double-click, press Enter or click Properties in the contect menu)
open the Environment tab
Process Explorer is displaying all environment variables in a single list, but Process Hacker organizes them into three sections by their scope:
Process: environment variables specific to the current process (e.g. passed from the command line or defined during the process creation
User: environment variables defined for the user who owns the process
System: system-wide environment variables shared by all processes
Take a look at the _environ variable.
To get process environment, you must be able to obtain its context. And within the context, use getenv() to get specific variable.

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