Delete part of the Path registy value

1

I have this registry value:

[HKEY_CURRENT_USER\Environment]

"Path"="C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\Windows\\system32;C:\\Program Files\\Amazon\\cfn-bootstrap\\;C:\\ProgramData\\chocolatey\\bin;C:\\Program Files (x86)\\PuTTY\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Amazon\\AWSCLI\\bin\\;C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI2\\wbin;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\blp\\DAPI"

I want to remove only C:\\blp\\DAPI using CMD bat file

scripter

Posted 2019-04-18T13:30:06.733

Reputation: 21

Why don't you just set the PATH variable to the new value that does not include the value you are removing? – Ramhound – 2019-04-18T13:34:59.340

@Ramhound: That's literally how removing a value works, but I would guess that the original value might contain unknown paths / differ from system to system, so a static .reg file wouldn't work as well as a dynamic tool. – user1686 – 2019-04-18T13:38:44.183

Thanks for comment, that value is created at every reboot, and it needs to be removed – scripter – 2019-04-18T13:40:33.330

@grawity - It sounds like the author wants a script, that will parse the variable for each value, then set the variable to the new value without that particular path. If the PATH system variable is being updated, then the software is adding the path to the variable, which means you will have to remove that software to stop the behavior. Have you identified what software uses that particular path? – Ramhound – 2019-04-18T13:43:19.003

Yes, i did, but no idea how to stop it from re-creating it, so i though this would be the easiest solution, just to remove C:\blp\DAPI from path – scripter – 2019-04-18T13:44:35.300

@scripter - You don't need a script to do that. You can do that, but if a program is automatically adding the path back to the variable, you have to remove the software before you remove it. – Ramhound – 2019-04-18T13:48:54.037

idea is to run script on some time interval – scripter – 2019-04-18T13:49:40.783

Sounds like a XY Problem to me. You may need to specify which app is creating that path.

– CaldeiraG – 2019-04-18T13:50:10.630

@scripter if that question solved your problem, please make a answer with that link so others users struggling with the same problem can see what you did. – CaldeiraG – 2019-04-18T13:56:51.317

Answers

1

Solved it by using Powershell:

$path = [System.Environment]::GetEnvironmentVariable(
    'PATH',
    'User'
)

$path = ($path.Split(';') | Where-Object { $_ -ne 'C:\blp\DAPI' }) -join ';'
# Set it
[System.Environment]::SetEnvironmentVariable(
    'PATH',
    $path,
    'User'
)

Source

scripter

Posted 2019-04-18T13:30:06.733

Reputation: 21