Environment Setting Windows

0 views
Skip to first unread message

Kassim Bisaillon

unread,
Aug 3, 2024, 5:05:39 PM8/3/24
to tinohindflat

The characters , , &, and ^ are special command shell characters, and they must be preceded by the escape character (^) or enclosed in quotation marks when used in (for example, "StringContaining&Symbol"). If you use quotation marks to enclose a string that contains one of the special characters, the quotation marks are set as part of the environment variable value.

Use environment variables to control the behavior of some batch files and programs and to control the way Windows and the MS-DOS subsystem appears and works. The set command is often used in the Autoexec.nt file to set environment variables.

If you use the set command without any parameters, the current environment settings are displayed. These settings usually include the COMSPEC and PATH environment variables, which are used to help find programs on disk. Two other environment variables used by Windows are PROMPT and DIRCMD.

If you specify values for and , the specified value is added to the environment and is associated with that variable. If the variable already exists in the environment, the new string value replaces the old string value.

If you use logical (&& or ) or modulus (%) operators, enclose the expression string in quotation marks. Any non-numeric strings in the expression are considered environment variable names, and their values are converted to numbers before they're processed. If you specify an environment variable name that isn't defined in the current environment, a value of zero is allotted, which allows you to perform arithmetic with environment variable values without using the % to retrieve a value.

If you call a variable value from a batch file, enclose the value with percent signs (%). For example, if your batch program creates an environment variable named BAUD, you can use the string associated with BAUD as a replaceable parameter by typing %baud% at the command prompt.

The set command assigns everything that follows the equal sign (=) to the value of the variable. Therefore, if you type set testVar=TEST^1, you'll get the following result, testVar=TEST1.

You can then use the string c:\directory in batch files by enclosing the name include with percent signs (%). For example, you can use dir %include% in a batch file to display the contents of the directory associated with the include environment variable. After this command is processed, the string c:\directory replaces %include%.

(Note: Other answers don't specifically address Windows 10 - at least not yet - and they leave off important steps - like how to open the control panel - that changed since previous versions of Windows.)

If by "system environment variables" you refer specifically to system-wide environment variables, then other answers have already covered this. However, if you want to edit both system-wide and user-specific environment variables then most (if not all) of these answers are inapplicable in general case.

If your user has administrator rights, you will be able to edit both sections of that dialog: user-specific environment variables (upper section) and system-wide environment variables (lower section). If you don't have administrator rights, you will only be able to edit the upper section: your own user-specific environment variables.

Unfortunately, Windows 10 November update (version 1511) destroyed this functionality. The Change my environment variables link no longer works. It is there, but it is dead. So for the post-November version of Windows 10 the correct answer is: it is generally impossible to edit user-specific environment variables in version 1511 of Windows 10 from regular user accounts. Microsoft has destroyed Windows 10 with this update and Windows 10 is now unusable. It will remain the case until they fix these ridiculous bugs in 1511 version of the OS.

I also experience the problem described by many users in this thread, i.e. the link to the dialogue to set the environment variables of non-admin users is dead. As a simple workaround I have downloaded this nice tool:

In windows 10, changing the environment variables has not changed, It is the same as in windows 7:Right click on This PC (My Computer).Left Click Properties.Left Click Advanced system settings.Left Click Environment Variables...

Environment variables are global system variables accessible by all the processes/users running under the Operating System (OS), such as Windows, macOS and Linux. Environment variables are useful to store system-wide values, for examples,

When you launch an executable program (with file extension of ".exe", ".bat" or ".com") from the CMD shell, Windows searches for the executable program in the current working directory, followed by all the directories listed in the PATH environment variable. If the program cannot be found in these directories, you will get the following error:

Environment variables in macOS/Unixes are case-sensitive. Global environment variables (available to ALL processes) are named in uppercase, with words joined with underscore (_), e.g., JAVA_HOME. Local variables (available to the current process only) are in lowercase.

Most of the Unixes and macOS use the so-called Bash Shell in the "Terminal". When you launch an executable program (with file permission of executable) in a Bash shell, the system searches the program in ALL the directories listed in the PATH. If the program cannot be found, you will get the following error:

Many problems in the installation and running of Java applications are caused by incorrect setting of environment variables (global system variables available to all the processes/users running under the Operating System), in particular, PATH, CLASSPATH and JAVA_HOME.

When you launch a program from the command line, the Operating System uses the PATH environment variable to search for the program in your local file system. In other words, PATH maintains a list of directories for searching executable programs.

For example, if you are trying to use Java Compiler "javac.exe" to compile a Java source file, but "javac.exe" cannot be found in the current directory and all the directories in the PATH, you will receive the following error:

The JDK's "bin" directory should be listed before "c:\windows\system32" and "c:\windows" in the PATH. This is because some older Windows systems provide their own Java runtime (which is often outdated) in these directories (try search for "java.exe" in your computer, you may find a few entries).

For ease of distribution, Java classes are often archived (zipped) together into a so-called JAR file. To use a third-party Java package, you need to place the distributed JAR file in a location that is available to the Java Compiler and Java Runtime.

If the Java Runtime ("java") cannot find the classes used in your program in all the above places, it will issue error "Could not find or load main class xxxx" (JDK 1.7) or "java.lang.NoClassDefFoundError" (Prior to JDK 1.7).

Notes: External native libraries (".lib", ".dll", ".a", ".so") are to be found in a path in JRE's Property "java.library.path", which normally but not necessarily includes all the directories in the PATH environment variable. Otherwise, you will get a runtime error "java.lang.UnsatisfiedLinkError: no xxx in java.library.path".

The CLASSPATH environment variable could include directories (containing many class files) and JAR files (a single-file archive of class files). If CLASSPATH is not set, it is defaulted to the current directory. If you set the CLASSPATH, it is important to include the current working directory (.). Otherwise, the current directory will not be searched.

A common problem in running hello-world program is: CLASSPATH is set but does not include the current working directory. The current directory is therefore not searched, which results in "Error: Could not find or load main class Hello". You can simply remove the CLASSPATH, and leave the class path defaulted to the current directory.

For a beginner, no explicit CLASSPATH setting is required. The default CLASSPATH setting of current directory is sufficient. Remove all CLASSPATH setting if there is any. However, if you have to set CLASSPATH, make sure that you include the current directory '.'.

You'll need to close and re-open any command windows that were open before you made these changes, as there's no way to reload environment variables from an active command prompt. If the changes don't take effect after reopening the command window, restart Windows.

Remember to replace PATH with the name of the environment variable you want to check. For instance, in the following screenshot, we used the echo %OS% to print the value of the environment variable.

The Windows Registry is the central database in Windows, storing configurations for the OS, software, and hardware. You can easily unset or delete environment variables in Windows by editing the relevant entry in the Registry.

Setting, unsetting, or modifying environment variables with the right approach can effectively tailor your system to specific needs. It involves various methods, from using the GUI to editing the Registry. Whether through a user-friendly interface or more advanced settings, always exercise caution to ensure system stability.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages