0

I'm working on a PowerShell script to install the Oracle client 19c. One of the things I need to do in the script before the install starts is to remove an environment variable from the Windows registry. This is the command I am using in the script to do this:

Remove-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "ORACLE_BASE" -Force

The problem is when the install starts later in the script it still thinks that setting is there, even though after the script is done running the setting is no longer there when I look. So I'm thinking I need to run that command in a special instance or something so it takes effect right away. Just not sure the best way to do that. I've tried using both start-process and invoke-expression to launch powershell within the script and neither method seems to do the trick. Any help would be much appreciated!

3
  • Why does it matter if the ORACLE_BASE environment variable is defined when you start the install? Commented Aug 5, 2020 at 22:06
  • Because it changes the install behavior by installing the Oracle inventory into the location of that variable path, which I don't want. Commented Aug 5, 2020 at 22:48
  • In that case, simply remove the environment variable from the process that's starting your installer (see my answer, which describes how to do it from a cmd.exe or PowerShell shell). Commented Aug 5, 2020 at 22:50

1 Answer 1

2

The problem is when the install starts later in the script it still thinks that setting is there, even though after the script is done running the setting is no longer there when I look. So I'm thinking I need to run that command in a special instance or something so it takes effect right away.

Your assumption is not correct.

Environment variables for an executable are inherited from the process that started the executable. Removing the environment variable from the registry will not make it disappear from the current process. This is why "it still thinks the setting is there."

If you really need the variable not to be present in the environment when starting the install, then unset it from a shell and run the installer:

  • cmd.exe shell script/batch:

     set ORACLE_BASE=
    
  • PowerShell:

    Remove-Item Env:ORACLE_BASE -ErrorAction SilentlyContinue
    

    -ErrorAction SilentlyContinue can be shortened to -EA 0 (it prevents an error message if the variable isn't in the environment).

After removing the variable (use the command above that matches your shell), then start the installer from that shell. Then the installer inherits the environment from the shell, and thus the variable will not be defined in the installer's process.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.