Tuesday, 14 January 2025

Environment Variables not working in Windows 11 - SOLVED

Environment Variables play an important part in running things on OS. Especially for windows, it's entire working is dependent on them. The most basic segregation you might have seen is between SYSTEM variables and USER variables inside Environment Variables window. But they have very wide usage like,

Configuration: They allow programs to access settings and configurations without hardcoding them into the source code.

Customization: Users can tailor their environment by setting variables that affect how programs behave.

Security: Sensitive information like passwords or API keys can be stored in environment variables, keeping them out of source code.

Flexibility: Changes to settings can be made globally or per-user without modifying the programs themselves.

Isolation: Different processes can have their own set of environment variables, providing a degree of isolation.

Problem noticed in Windows 11:

I was trying to create a batch script on my personal laptop, running on Windows 11, and I noticed something weird. I was setting some variables in the script and when I ran it, those variables were not displaying any value. I had never seen something like this before so I googled like every other tech person & thanks to Microsoft's different forums, I found nothing that could help.

Solution:

It's a silly thing actually that Terminal runs on Powershell with black screen which mimics Command Prompt theme and is the root cause here. So all you need to do it run cmd command on terminal and it starts doing what it is supposed to.

For Example,

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows

PS C:\Users\parvi> echo %TEMP%
%TEMP%
PS C:\Users\parvi> cmd
Microsoft Windows [Version 10.0.26100.2605]
(c) Microsoft Corporation. All rights reserved.

C:\Users\parvi>echo %TEMP%
C:\Users\parvi\AppData\Local\Temp

C:\Users\parvi>echo %TMP%
C:\Users\parvi\AppData\Local\Temp

C:\Users\parvi>

Silly right !! Anyway I hope this fixes your problem.

If you are smarter than me and if your problem is something else which I have not covered, put a comment and I'll try to help.

No comments:

Post a Comment