- How to Add to Windows PATH Environment Variable
- Add Directories to PATH Variable
- Change location of TEMP files folder to another drive
- How to get temporary folder for current user
- 4 Answers 4
- Creating a temporary directory in Windows?
- 9 Answers 9
- How to get the Windows temporary directory
- TEMP environment variable
- GetTempPath API function
How to Add to Windows PATH Environment Variable
Works for Windows 10 or 7
If you’re a coder or programmer, you probably spend a decent amount of time using the command prompt to execute programs or compile code. In order to complete those tasks, you most likely have to use a command from a library or software package installed (like Python) on your system.
By default, most of these programs will add their own custom shortcuts to the Windows environment variables. The most used environment variable in Windows is probably the PATH variable. It basically allows you to run any executables that are located inside the paths specified in the variable at the command prompt without having to give the full path to the executable.
In this article, I’ll show you how you can add more paths to the Windows PATH variable in case you want to run executables from your own custom directories. It’s worth noting that the procedure below is for Windows 10, but it’s almost exactly the same for Windows 7 also.
Add Directories to PATH Variable
To get started, right-click on the Computer or This PC icon on the desktop and select Properties. If you don’t have that icon on your desktop already, you can add any missing desktop icons easily.
On the System dialog page, you’ll see an Advanced system settings link on the left-hand side.
This will bring up the System Properties dialog, which should already be open to the Advanced tab. Go ahead and click on the Environment Variables button at the very bottom.
On the Environment Variables dialog, you’ll see two sets of variables: one for user variables and the other for system variables. Both lists have the PATH variable, so you have to decide which one to edit.
If you only need the commands for your own user account, then edit the user variable. If you need it to work across the computer system regardless of which user is logged in, then edit the system variable. Click on Path and then click on Edit.
On the Edit environment variable dialog, you’ll see a list of all the paths that are currently in the PATH variable. As you can see, Node.js and Git already added their paths so that I can run Git commands and Node.js commands from anywhere while in the command prompt.
To add a new path, simply click on New and it’ll add a new line to the bottom of the list. If you know the path, simply type it in or copy and paste it. If you prefer, you can also click Browse and then navigate to the desired path.
To edit any path, simply select it and then click on the Edit button. You can also delete paths using the Delete button. Note that you can also move items up and down on the list. When you type a command at the command prompt, Windows has to search through each directory stored in the PATH variable to see if that executable exists or not. If you want your executable to be found faster, just move that path up to the top of the list.
This can also come in handy if you have multiple versions of the same command in different paths and need to have one run instead of the other. The one that shows up higher in the list will be run when you type in the command.
Lastly, if you click on Edit text, it will load a dialog where you can edit the Path variable using the old interface where all the paths are listed in one text box.
That’s all there is to it! If you want to learn more about environment variables, make sure to check out my post on how to create your own custom environment variables. Enjoy!
Founder of Help Desk Geek and managing editor. He began blogging in 2007 and quit his job in 2010 to blog full-time. He has over 15 years of industry experience in IT and holds several technical certifications. Read Aseem’s Full Bio
Change location of TEMP files folder to another drive
1. What are the steps (dialogue) to change Windows7 system TEMP files on C-drive to one of my other local HHD drives? I now have only a 160GB SSD for my boot (C-drv) and want to keep the WRITE/ERASE ops down to a minimum.
2. Is it a security risk to change the Internet TEMP file Folder from the hidden/protected area on the C-drive to another local HHD? I have read that there are built-in virtual paths and protectors both on the system and registry which tends to protect from internet TEMP files contains viruses, rootkits, etc from reaching the critical areas easily. Also Norton likely checks signatures in these default areas for TEMP files.
Thanks in advance.
Core i7-975 3.33GHz, 12GB RAM, nVidia GTX280m, Win7 Ultimate64
To change the location of the System Temp folder, follow the steps given below.
1. Right click on Computer and click on Properties. In the resulting window with the basic information about your computer
2. Click on Advanced system settings on the left panel resulting in a dialog box click on the Advanced tab a
3. Click on the button near the bottom labeled Environment Variables.
4. You may see both TMP and TEMP listed in the section labeled User variables for (account). That’s the common location; each different login account is assigned its own temporary location.
5. In the Variable value Edit box you may specify the path to the directory that Windows and many other programs will use for temporary files.
Be sure and repeat that process for both TMP and TEMP.
You’ll need to restart any running programs for the new value to take effect. In fact, you’ll need to restart Windows for it to begin using the new value for its own temporary files.
To change the location of the Internet Temp folder, follow the steps given below.
Note: That Internet Explorer moves cookies to the new folder and the old folder is removed. Additionally, the following message is displayed when you attempt to move the Temporary Internet Files folder:
Warning: Moving the location of your Temporary Internet Files folder will delete all your subscription data.
- Create a new folder to store the files. For example, if you want to store the files in a folder named Ietemp on drive D, create the following folder:
For information about how to create a folder, click Start, click Help, click the Index tab, type new folder, and then double-click the «New Folders» topic.
- Start Internet Explorer.
- On the Tools menu, click Internet Options.
- On the General tab, click Settings.
- Click Move Folder.
- Click the folder you created in Step 1.
- Click OK, click OK, and then click OK again.
- Restart your computer
You can change the location of Internet explorer temp folder; there is no security threat to your computer.
Hope this information is helpful.
Microsoft Answers Support Engineer
Visit our Microsoft Answers Feedback Forum and let us know what you think.
How to get temporary folder for current user
Currently I am using following function to get the temporary folder path for current user:
On some machines it gives me temp folder path of current user like:
C:\Documents and Settings\administrator\Local Settings\Temp\
On some machines it gives me system temp folder path like:
MSDN Documentation also says that above API returns current system’s temporary folder.
Is there any other API available which gives me current user’s temporary folder path like this:
C:\Documents and Settings\administrator\Local Settings\Temp\
4 Answers 4
System.IO.Path.GetTempPath() is just a wrapper for a native call to GetTempPath(..) in Kernel32.
Copied from that page:
The GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
It’s not entirely clear to me whether «The Windows directory» means the temp directory under windows or the windows directory itself. Dumping temp files in the windows directory itself sounds like an undesirable case, but who knows.
So combining that page with your post I would guess that either one of the TMP, TEMP or USERPROFILE variables for your Administrator user points to the windows path, or else they’re not set and it’s taking a fallback to the windows temp path.
Creating a temporary directory in Windows?
What’s the best way to get a temp directory name in Windows? I see that I can use GetTempPath and GetTempFileName to create a temporary file, but is there any equivalent to the Linux / BSD mkdtemp function for creating a temporary directory?
9 Answers 9
No, there is no equivalent to mkdtemp. The best option is to use a combination of GetTempPath and GetRandomFileName.
You would need code similar to this:
57 bits. You can always make two calls to square it – Marty Neal Jul 25 ’13 at 17:05
I hack Path.GetTempFileName() to give me a valid, pseudo-random filepath on disk, then delete the file, and create a directory with the same file path.
This avoids the need for checking if the filepath is available in a while or loop, per Chris’ comment on Scott Dorman’s answer.
If you truly need a cryptographically secure random name, you may want to adapt Scott’s answer to use a while or do loop to keep trying to create a path on disk.
I like to use GetTempPath(), a GUID-creation function like CoCreateGuid(), and CreateDirectory().
A GUID is designed to have a high probability of uniqueness, and it’s also highly improbable that someone would manually create a directory with the same form as a GUID (and if they do then CreateDirectory() will fail indicating its existence.)
@Chris. I too was obsessed with the remote risk that a temporary directory might already exist. The discussions about random and cryptographically strong don’t completely satisfy me either.
My approach builds on the fundamental fact that the O/S must not allow 2 calls to create a file to both succeed. It is a little surprising that .NET designers chose to hide the Win32 API functionality for directories, which makes this much easier, because it does return an error when you attempt to create a directory for the second time. Here is what I use:
You get to decide whether the «cost/risk» of unmanaged p/invoke code is worth it. Most would say it is not, but at least you now have a choice.
How to get the Windows temporary directory
There are at least two ways to get the Windows temporary directory folder (i.e. that folder in which by convention applications may freely create temporary files):
TEMP environment variable
The TEMP environment variable dates back to the pre-windows days of DOS, but is still used and available in windows applications. By convention both the variables TMP and TEMP indicate the temporary directory. The values of these variables can be easily read using the GetEnvironmentVariable function, i.e.:
- You will need to include SysUtils to use the GetEnvironmentVariable function. The version in SysUtils places a wrapper around the API version of the function defined in the unit Windows (which takes different parameters).
GetTempPath API function
The Windows API function GetTempPath returns the path to the Windows temporary file folder. The GetTempPath function is defined in the Windows unit and its definition looks like:
function GetTempPath(nBufferLength: Cardinal; lpBuffer: PChar): Cardinal;
This takes a buffer and the size of the buffer and writes the temporary folder into the buffer, returning the number of characters written to the buffer.
Personally I don’t find this useful, because I prefer to be able to assign the value to a variable directly. For this reason I use a wrapper function:
This lets you do more intuitive assignments such as
- GetTempPath and MAX_PATH are defined in the unit Windows.
- StrPas is defined in the unit SysUtils .
These notes are believed to be correct for Delphi 6 and Delphi 7 and may apply to other versions as well.
About the author: Brian Cryer is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.