How to Delete Stale Windows SMB Shares When Source Folder No Longer Exists


11 views

When administering Windows servers or workstations, you've likely encountered stubborn SMB shares that refuse to be deleted through Computer Management or PowerShell. The classic error message "The system cannot find the path specified" appears when the original shared folder was deleted without properly removing the share first.

Windows maintains share information in the registry at HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares. When the physical folder disappears but the registry entry remains, you get these orphaned shares.

Here are three effective approaches to remove these phantom shares:

Method 1: Using Registry Editor

1. Press Win+R, type "regedit"
2. Navigate to:
   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares
3. Delete the problematic share key
4. Restart the Server service or reboot

Method 2: PowerShell Script

# First list all shares to identify the problematic ones
Get-SmbShare | Format-Table Name,Path,Description

# Then force remove the stale share
Remove-SmbShare -Name "ProblemShare" -Force

# Alternative using WMI for older systems
$share = Get-WmiObject -Class Win32_Share -Filter "Name='ProblemShare'"
$share.Delete()

Method 3: NET Command Line

:: View all shares
net share

:: Delete specific share (admin CMD required)
net share ProblemShare /delete /y

For system administrators dealing with multiple servers, here's a script to find and remove all invalid shares:

$shares = Get-SmbShare | Where-Object { $_.Path -ne $null }
foreach ($share in $shares) {
    if (-not (Test-Path $share.Path)) {
        Write-Host "Removing stale share: $($share.Name)"
        Remove-SmbShare -Name $share.Name -Force
    }
}
  • Always remove shares before deleting folders
  • Document share configurations
  • Consider using DFS Namespaces for better management
  • Implement change control procedures

We've all encountered this - shares that refuse to disappear from Computer Management even after their source folders are long gone. Windows throws the frustrating "The system cannot find the path specified" error when attempting removal. These orphaned SMB shares can clutter your system and potentially cause conflicts.

Windows maintains share information in the registry (HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares) and through internal SMB server structures. When the physical path validation fails, the GUI management tools become useless, but we can dive deeper.

The net share command is our most powerful weapon here. First, list all shares to identify the problematic ones:

net share

Then force delete the invalid share (replace SHARENAME with your target):

net share SHARENAME /delete

If the command line approach fails, we need to manually remove registry entries:

  1. Open regedit and navigate to:
    HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares
  2. Find the problematic share (data will show the original path)
  3. Right-click → Delete the entire key
  4. Restart the Server service or reboot

For system administrators managing multiple machines, this PowerShell script can identify and remove invalid shares:

Get-SmbShare | Where-Object {
    try { Test-Path $_.Path -ErrorAction Stop } 
    catch { $false }
} | Remove-SmbShare -Force

Best practices to avoid this situation:

  • Always remove shares before deleting folders
  • Consider using DFS Namespaces for more resilient shares
  • Document all share creations in your change management system