See the question and my original answer on StackOverflow

One solution is to test whether the Shell Folder (IShellFolder) beneath the Shell View that Windows sends back is handled by the Windows file system or by some custom folder.

For that, you can use the System.NamespaceCLSID Windows property. If the folder associated with the view is handled by the file system, this property value will be the ShellFSFolder GUID value which equal to f3364ba0-65b9-11ce-a9ba-00aa004ae837 (from Windows SDK shobjidl_core.h).

You can test it with something like this in PowerShell:

$ShellFSFolder = [System.Guid]::New("f3364ba0-65b9-11ce-a9ba-00aa004ae837")

foreach($win in (New-Object -com "Shell.Application").Windows()) {
    $clsid = $win.Document.Folder.Self.ExtendedProperty("System.NamespaceCLSID")
    if ($clsid -ne $null) {
        $clsid = [System.Guid]::New($clsid)
        if ($clsid -eq $ShellFSFolder) {
            Write-Host $win.Document.Folder.Self.Path
        }
    }
}

And like this in C#:

var ShellFSFolder = new Guid("f3364ba0-65b9-11ce-a9ba-00aa004ae837");

dynamic shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
foreach (var win in shell.Windows)
{
    var clsid = win.Document.Folder.Self.ExtendedProperty("System.NamespaceCLSID");
    if (clsid != null)
    {
        Guid guid;
        if (clsid is byte[] bytes)
        {
            guid = new Guid(bytes);
        }
        else
        {
            guid = new Guid((string)clsid);
        }
        
        if (guid == ShellFSFolder)
        {
            Console.WriteLine(win.Document.Folder.Title); // for example
        }
    }
}