Environment variables are not often seen directly when using Windows. However there are cases, especially when using the command line, that setting and updating environment variables is a necessity. In this series we talk about the various approaches we can take to set them. In this article we look at how to interface with environment variables using the Command Prompt and Windows PowerShell. We also note where in the registry the environment variables are set, if you needed to access them in such a fashion.
Administrator C Windows System32 Cmd Exe Download
Print environment variables
You can use environment variables in the values of other environment variables. It is then helpful to be able to see what environment variables are set already. This is how you do it:
List all environment variables
C: Windows System32 otepad.exe. System32 is where you will find stock Windows desktop apps whereas third-party apps like Chrome will be in Program Files (x86) or Program Files. Run An App On The Login Screen. On your desktop, open Command Prompt with administrative rights and run the following command; psexec -sx cmd.exe.
Print a particular environment variable:
List all environment variables
Print a particular environment variable:
- CMD.exe/Command Prompt Keeps Popping up in Windows 10, How to Stop and Fix It? 'Hi guys, have you ever met this problem that Command Prompt keeps popping up with a black window which shows a pathway: c: windows system32 cmd.exe. I closed the window, but it popped up right away.
- Click on Start-Run, type: msconfig, then click on OK.When the System Configuration Tool loads, click on the 'Startup' tab, then see if ' c: WINDOWS system32 cmd.exe' is listed there.
Set Environment Variables
To set persistent environment variables at the command line, we will use
setx.exe. It became part of Windows as of Vista/Windows Server 2008. Prior to that, it was part of the Windows Resource Kit. If you need the Windows Resource Kit, see Resources at the bottom of the page.
setx.exe does not set the environment variable in the current command prompt, but it will be available in subsequent command prompts.
Open a new command prompt.
To edit the system variables, you’ll need an administrative command prompt. See HowTo: Open an Administrator Command Prompt in Windows to see how.
The location of the user variables in the registry is:
HKEY_CURRENT_USEREnvironment. The location of the system variables in the registry is:
When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.
One way is to get this message issued is to open the environment variables in the GUI, like we do in HowTo: Set an Environment Variable in Windows - GUI; we do not need to change anything, just open the
Environment Variables window where we can see the environment variables, then hit
Another way to get the message issued is to use
setx, this allows everything to be done on the command line, however requires setting at least one environment variable with
Printing Environment Variables
With Windows XP, the
reg tool allows for accessing the registry from the command line. We can use this to look at the environment variables. This will work the same way in the command prompt or in powershell. This technique will also show the unexpanded environment variables, unlike the approaches shown for the command prompt and for powershell.
First we’ll show the user variables:
We can show a specific environment variable by adding
/v then the name, in this case we’ll do
Now we’ll list the system environment variables:
And same as with the user variables we can query a specific variable.
Unsetting a Variable
When setting environment variables on the command line,
setx should be used because then the environment variables will be propagated appropriately. However one notable thing
setx doesn’t do is unset environment variables. The
reg tool can take care of that, however another
setx command should be run afterwards to propagate the environment variables.
The layout for deleting a user variable is:
reg delete HKEY_CURRENT_USEREnvironment /v variable_name /f. If
/f had been left off, we would have been prompted:
Delete the registry value EXAMPLE (Yes/No)?. For this example we’ll delete the user variable
Deleting a system variable requires administrator privileges. See HowTo: Open an Administrator Command Prompt in Windows to see how to do this.
The layout for deleting a system variable is:
reg delete 'HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerEnvironment' /v variable_name /f. For this example we’ll delete the system variable
If this was run as a normal user you’ll get:
But run in an administrator shell will give us:
C Windows System32 Cmd.exe Download
Finally we’ll have to run a
setx command to propagate the environment variables. If there were other variables to set, we could just do that now. However if we were just interested in unsetting variables, we will need to have one variable left behind. In this case we’ll set a user variable named
throwaway with a value of
Windows Server 2003 Resource Kit Tools will also work with Windows XP and Windows XP SP1; use Windows XP Service Pack 2 Support Tools with Windows XP SP2. Neither download is supported on 64-bit version.
Parts in this series
- HowTo: Set an Environment Variable in Windows - Command Line and Registry
- Basic Chocolatey Commands
What is Chocolatey?
Chocolatey or Choco as it is sometimes referred to, is a free, open-source package manager for Windows that is very similar to Apt or DNF in the Linux realm. In other words, this is a program used for installing software via the Windows command line. It downloads a program, installs it, then it will check for updates, and installs those updates automatically if needed. Those who use Linux are quite familiar with the package management systems like this.
Some ask, “Why should we choose to use a program like this, since we can simply download the .exe or .msi software and install the program ourselves?”
That is an excellent question. Here are several solid answers.
- When we install a new operating system and want to use numerous programs, we must look for each program installer, download it, install it, and then regularly check for updates. The Chocolatey package manager this all by itself, when using automatic mode.
- Instead of searching for an executable installer, we can install the program using the Chocolatey package manager and complete everything using the command line. It is much more convenient and faster.
- We can conveniently and more comfortably control the application versions we need. Most often, when we go to download an executable for the application, it downloads the latest version for us, and we do not always need the latest version.
- Chocolatey provides clear, simple commands which are almost identically used in all package management systems.
- Windows 7 or later / Windows Server 2003 or later
- PowerShell v2 or later
- .NET Framework 4 or later
(As an aside, the installation will attempt to install .NET 4.0 if you do not have it already installed.)
Let’s move on to the installation. There are two options for installing Chocolatey. We can install Chocolatey via the command line or through PowerShell. The option to use cmd is most often used for Windows, and PowerShell for running scripts. In this case, we can run both cmd and PowerShell, but as an administrator, for this installation.
Install Using Powershell
When installing the software via PowerShell, we must ensure the local
is not set to restricted. Chocolatey suggests using
to bypass the policy to get things installed or
for increased security.
First, we need to run.
If it returns
Then we need to run
Set-ExecutionPolicy Bypass -Scope Process.
Now run the following command in the Windows shell.
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
If there are no errors, Chocolatey will be installed. We can verify the installation using one of the following commands.
Install Using Windows Cmd Shell
First, we need ensure that we are using an administrative shell.
Next, copy the following command to our cmd.exe shell.
@'%SystemRoot%System32WindowsPowerShellv1.0powershell.exe' -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command ' [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))' && SET 'PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin'
And then press enter.
The installation should look something like this.
Microsoft Windows [Version 10.0.18363.900]
(c) 2019 Microsoft Corporation. All rights reserved.
C:WINDOWSsystem32>@'%SystemRoot%System32WindowsPowerShellv1.0powershell.exe' -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command ' [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))' && SET 'PATH=%PATH%;%ALLUSERSPROFILE%chocolateybin'
Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.15.
Extracting C:UsersuserAppDataLocalTempchocolateychocInstallchocolatey.zip to C:UsersuserAppDataLocalTempchocolateychocInstall...
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
Setting ChocolateyInstall to 'C:ProgramDatachocolatey'
WARNING: It's very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:ProgramDatachocolateylib'
A shim file for the command line goes to 'C:ProgramDatachocolateybin'
and points to an executable in 'C:ProgramDatachocolateylibyourPackageName'.
Creating Chocolatey folders if they do not already exist.
WARNING: You can safely ignore errors related to missing log files when
upgrading from a version of Chocolatey less than 0.9.9.
'Batch file could not be found' is also safe to ignore.
'The system cannot find the file specified' - also safe.
WARNING: Not setting tab completion: Profile file does not exist at
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
To verify that Chocolatey is installed, we will use the choco command.
Please run 'choco -?' or 'choco -?' for help menu.
Excellent! Chocolatey is installed!
Basic Chocolatey Commands
Now let’s review some of the basic commands for using Choco. Choco commands can be used in both the Windows cmd shell and in PowerShell.
To install a specific program, use the following command.
choco install <pkg packages.config> [ ] </pkg packages.config>
choco install chrome
For a complete listing of install options, visit the Choco install page or run the following command.
choco install -h
To update a program, we will use the following command.
choco upgrade <pkg all> [ ] </pkg all>
сhoco upgrade chrome
Update All Programs
To update all programs, we need to use the following command.
cup <pkg all> [ ] </pkg all>
choco upgrade all
If you noticed, the cup command is an alternative to using the choco upgrade command.
Search For a Program
To find a needed program for downloading and installation, we can enter the following command.
choco search chrome
See Installed Programs
Using the following command, you can see which programs are already installed using Choco.
choco list --local-only
5 packages installed.
We can update the Choco program itself using this command.
choco upgrade chocolatey
It is important to do this periodically because in previous versions, errors may be detected, and they need to be fixed so that there are no vulnerabilities.
Install the Chocolatey GUI
If someone is not comfortable using the command line, we can install the graphical user interface of Chocolatey using this command.
choco install chocolateygui
That’s it! As you can see, using Chocolatey is very simple. Overall, we have found that Chocolatey is an excellent tool in our local systems administration toolbox. It is reliable, definitive, and consistently updated. Overall, it is an exceptional product.