0X40000000

STATUS_OBJECT_NAME_EXISTS (0X40000000): Quick Fixes

You tried to create a file, folder, or registry key that already exists. Usually a race condition or leftover artifact. Here's how to clear it fast.

1. File or Folder Already Exists (Most Common)

This is the culprit in about 80% of cases. Something tried to CreateFile or CreateDirectory and the target path already exists. Happens a lot during installers, backup scripts, and batch file runs.

I see it most often when someone runs a deployment script twice, or when a service is restarting and tries to recreate its own temp folder.

Fix: Delete or Rename the Existing Object

  1. Open File Explorer and navigate to the path from the error message.
  2. If it's a file, check if it's locked by another process (use Process Explorer or handle.exe from Sysinternals).
  3. Delete or rename the object. If it's locked, kill the locking process first.
  4. Retry the operation that failed.

For scripts and installers, add a check before creation:

if exist "C:\path\to\file" del /f /q "C:\path\to\file"
md "C:\new\folder" 2>nul || echo Folder already exists, continuing...

If you're writing a C++ or .NET app, use CreateFile with OPEN_ALWAYS instead of CREATE_NEW to avoid this entirely.

2. Registry Key Conflict (Developer & Admin Scenario)

This one bites when you're using RegCreateKeyEx or RegSetValueEx with REG_OPTION_NON_VOLATILE and the key already exists. I've debugged this on Windows Server 2019 and Windows 10 22H2 builds.

Common trigger: a logon script tries to create a key under HKLM\Software\YourApp every time a user logs in. First run works, second run fires the error.

Fix: Check Existence Before Creating

  1. Open regedit and browse to the parent key.
  2. If the child key exists, delete it or modify the script to use RegOpenKeyEx instead.
  3. In PowerShell, use Test-Path before New-Item -Force:
$keyPath = "HKLM:\Software\YourApp"
if (-not (Test-Path $keyPath)) {
    New-Item -Path $keyPath -Force
}

For C++, call RegCreateKeyEx with REG_OPTION_OPEN_LINK if you just want to open an existing key without error.

3. Named Pipe or Mailslot Already Exists (Rare but Painful)

This shows up in inter-process communication. Two processes try to create the same named pipe at \\.\pipe\MyPipe. The second one gets 0X40000000.

I've seen it in custom services that spawn worker processes without proper synchronization.

Fix: Use Unique Pipe Names or Mutex

  1. Check your service code for hardcoded pipe names.
  2. Append the process ID or a GUID to the pipe name:
\\.\pipe\MyService_%d
  1. Or use a mutex to ensure only one instance creates the pipe:
CreateMutex(NULL, TRUE, "Global\MyPipeMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
    // Another instance already owns the pipe
}

Also, kill leftover orphaned pipes with handle.exe | findstr pipe from Sysinternals. That'll show you what's holding the pipe open.

Cause Symptoms Fix
File/folder exists Error during copy, install, or script Delete or rename; add check in script
Registry key exists Error in logon script or app installation Use Test-Path or OPEN_EXISTING
Named pipe already exists Error in multi-process service Unique pipe names or mutex sync
Related Errors in Windows Errors
0X00001129 0X00001129 Reparse Tag Invalid: Fix Invalid Tag Error 0X00000102 WAIT_TIMEOUT 0x102 – What It Means & How to Fix It 0XC0000181 STATUS_CHILD_MUST_BE_VOLATILE (0XC0000181) Fix 0X8000000A E_PENDING (0X8000000A) – Data Not Yet Available

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.