PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] Why when i edit PATH(enviroment variable) in cmd, l can't find changes in system property, but i can find in cmd?(windows10))

 November 05, 2022     batch-file, cmd, environment-variables, windows-10     No comments   

Issue

here is the path before edit:

echo %path%
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\WindowsApps;

Then i use cmd order path=%path%C:\Test; to add a new root to path.

After that, i echo %path% again, and i got this:

C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\WDAGUtilityAccount\AppData\Local\Microsoft\WindowsApps;C:\Test;

It looks good,Gight?.But when i go into system property.

I got this:

Problem:

Obviously, the new root C:\Test is not showing in the system property.

I want to know why and how to fix the problem.


Solution

To do what you were hoping to do, specifically appending to the existing System Environment %Path% variable, this is how I'd recommend you do it:

From cmd

For /F "EOL=H Tokens=2,*" %G In ('%SystemRoot%\System32\reg.exe Query "HKLM\SYSTEM\CurrentControlset\Control\Session Manager\Environment" /V Path 2^>NUL') Do @%SystemRoot%\System32\setx.exe Path "%HC:\Test;" /M

From a batch-file

@For /F "EOL=H Tokens=2,*" %%G In ('%SystemRoot%\System32\reg.exe Query
 "HKLM\SYSTEM\CurrentControlset\Control\Session Manager\Environment" /V Path
 2^>NUL') Do @%SystemRoot%\System32\setx.exe Path "%%HC:\Test;" /M

Please note: to do this, you'll need to run your cmd/batch-file elevated, i.e. "Run as administrator". Also this is designed to add your new directory location, only if there is already non space content within that variables value, (if there isn't your system is already broken). You should also note that the new variable content will only be available for future cmd.exe instances, not any currently running ones, (which were loaded prior to your change). If you wanted it available globally and local to the running session, you'd need to also include the separate command, Set "Path=%Path%C:\Test;"



Answered By - Compo
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,214,658

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing