How to Fix the SET_ENV_VAR_FAILED Bug Check 0x5B

Check if the environment variables are set correctly

Reading time icon 4 min. read


Readers help support Windows Report. We may get a commission if you buy through our links. Tooltip Icon

Read our disclosure page to find out how can you help Windows Report sustain the editorial team Read more

How to fix the SET_ENV_VAR_FAILED BSoD

The SET_ENV_VAR_FAILED error comes with the value of 0x0000005B and it is associated with problematic system environment variables. We have a few tested solutions that helped most of the users who encountered this BSoD.

How do I fix the SET_ENV_VAR_FAILED BSoD?

1. Checking system variables

  1. Press Win + X and select System from the menu.
  2. Click on Advanced system settings.
  3. In the System Properties window, click on the Environment Variables button.
  4. Check if any variables are missing or incorrectly set. Look through both user and system variables.
  5. If variables are missing or incorrect, add or modify the variables as necessary by clicking on New or Edit.

Ensuring that environment variables are correctly set can resolve issues related to system functionality and application performance since incorrect or missing variables may cause the SET_ENV_VAR_FAILED error.

2. Temporarily disable the third-party antivirus

  1. Open the antivirus program by double-clicking its icon in the taskbar or searching for it through the Start menu.
  2. Navigate to the settings or options menu within the antivirus software.
  3. Look for an option to temporarily disable the antivirus protection. This might be under sections like Real-time protection or Shield control.
  4. Disable the antivirus temporarily and check if the SET_ENV_VAR_FAILED error persists.

If the error resolves after disabling the antivirus, consider adding an exception for the affected application or switching to a different antivirus program.

Some antivirus programs may interfere with environment variable settings. Disabling the antivirus helps determine if it is the cause of the error.

3. Run a System File Checker (SFC) scan

  1. Type cmd in the Start menu, right-click on Command Prompt and select Run as administrator.
  2. In the Command Prompt window, type sfc /scannow and press Enter.
  3. Follow any instructions provided at the end of the scan.
  4. Restart your system and check if the error is resolved.

The System File Checker (SFC) tool scans for and restores corrupt system files. This can fix errors related to the misconfiguration of environment variables that lead to the SET_ENV_VAR_FAILED bug check.

4. Run the DISM tool

  1. Click the Start button, type cmd and select Run as administrator from the results.
  2. In the Command Prompt window, type the following command and press EnterDISM /Online /Cleanup-Image /RestoreHealth
  3. Restart your system once the process is finished.

The Deployment Imaging Service and Management Tool (DISM) repairs system image files and can resolve deeper system corruption that might be causing the SET_ENV_VAR_FAILED error.

5. Update device drivers

  1. Press Win + X and select Device Manager.
  2. Expand the categories to find the device you want to update (e.g., Display adapters, Network adapters). If you find a device that has a yellow exclamation mark next to it, treat it with priority.
  3. Right-click on the device and select Update driver.
  4. Choose Search automatically for drivers and follow the prompts.
  5. Repeat for all major devices to ensure they are up to date.

Outdated or incompatible drivers can cause various system errors, including the SET_ENV_VAR_FAILED bug check. Updating drivers ensures that all hardware components work correctly with the OS. It’s also very useful to check for any Windows updates and install them because they also come with new drivers.

6. Perform a Clean Boot

  1. Press Win + R, type msconfig, and press Enter.
  2. In the System Configuration window, go to the Services tab.
  3. Check Hide all Microsoft services and then click Disable all.
  4. Go to the Startup tab and click on Open Task Manager.
  5. Disable all startup items by right-clicking on each and selecting Disable.
  6. Close Task Manager and click OK in the System Configuration window.
  7. Restart your computer and check if the error persists.

Performing a clean boot helps identify if background services or startup programs are causing the SET_ENV_VAR_FAILED error by starting the computer with a minimal set of drivers and startup programs.

By following these steps, users can systematically troubleshoot and resolve the SET_ENV_VAR_FAILED error, ensuring their Windows system runs smoothly. To prevent similar issues in the future, regularly update your system and drivers, and periodically check your environment variables.

That being said, we have a guide on how to set environment variables in Windows 11. It will help you determine which ones are legitimate and which not.

You may also print environment variables using PowerShell to make things even easier.

For any other questions or suggestions, don’t hesitate to use the comments section below and leave a line.

More about the topics: BSoD error codes, BSoD errors