Tech Articles

List of all Environment Variables – Batch File Programming

Environment variables are special variables that contain its values set by the operating system itself, other applications or by manual. Environment variables are set to reduce tasks and code complexity by calling them in program, since they are just placeholders that keeps track of the system properties and system wide changes, and then sets its value. It holds values like drive path, currently logged in username, root drive, Operating System name and version and so on.

The following are the few environment variables set in Windows XP:

S.No Environment Variables Description
1 %ALLUSERSPROFILE% C:\Documents and Settings\All Users
2 %APPDATA% C:\Documents and Settings\{username}\Application Data
3 %CD% Current working directory
4 %CMDCMDLINE% Displays Windows Version
5 %CMDEXTVERSION% Command prompt version
6 %COMPUTERNAME% Equivalent to hostname command
7 %COMSPEC% C:\Windows\System32\cmd.exe
8 %DATE% Display current date
9 %ERRORLEVEL% Exit code for the previously executed command
10 %HOMEDRIVE% Root Drive
11 %HOMEPATH% \Documents and Settings\{username}
12 %NUMBER_OF_PROCESSORS% Displays number of processors
13 %OS% Displays the name of the OS installed
14 %PATH% Points to C:\WINDOWS\system32
15 %PATHEXT% .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH
16 %PROCESSOR_ARCHITECTURE% Displays the processor architecture
17 %PROCESSOR_LEVEL% Displays the processor level
18 %PROCESSOR_REVISION% Displays the processor revision
19 %PROMPT% Displays the current prompt
20 %RANDOM% Generates a random integer between 0 and 32767
21 %SYSTEMDRIVE% Moves to the Root drive
22 %SYSTEMROOT% C:\WINDOWS
23 %TEMP% and %TMP% C:\DOCUME~1\{USER}\LOCALS~1\Temp
24 %TIME% Displays current time
25 %USERDOMAIN% Displays the hostname
26 %USERNAME% Displays the currently logged in user name
27 %USERPROFILE% C:\Documents
28 %WINDIR% C:\WINDOWS

You can manually set an environment variable using the “SET” command and those variables set by this command will not reside permanently in the system but they were temporary and will be lost after a reboot.

To set an environment variable manually by using ‘set’ command,

C:\>set C=C:\windows\system32\cmd.exe
C:\>%C%

In the above example, We have set an environment variable name ‘C‘ and assigned the value the path to the command prompt. Then value can be accessed by using % on both sides of the variable like ‘%c%‘. Since I have set the path to the command prompt to the variable ‘c‘, when the variable is accessed, it will open up a new command prompt in the existing window.

Have something to say about this article? Comment below or share it with us on Facebook or Twitter.

H4ck0
Step by step hacking tutorials about wireless cracking, kali linux, metasploit, ethical hacking, seo tips and tricks, malware analysis and scanning.
https://www.yeahhub.com/

WHERE SHOULD WE SEND ?

HACKING TUTORIALS & INFOSEC NEWS?

Subscribe to Our Newsletter and Get Instant Delivered to Your Email Inbox.

We respect your privacy and take protecting it seriously.

Leave a Reply

Your email address will not be published. Required fields are marked *