The key is to compare against the window you want to keep instead of Self. App.Windows() returns every open window and <> compares window references, so it doesn't matter which window the code runs in.
Option 1: keep a reference to the main-menu window
Add a shared property to your App class so any window can reach it:
Class App Inherits DesktopApplication
# Other members as usual...
Shared Property MainMenu As MainMenuWindow
End Class
Have the main-menu window record itself when it opens:
Class MainMenuWindow Inherits Window
Event Opening()
App.MainMenu = Self
End Event
End Class
Then from any drill-down window, however deep, close everything except that reference:
For Each openWindow As Window In App.Windows()
If openWindow <> App.MainMenu Then
openWindow.Close()
End If
Next
Option 2: match by type with IsA
If there will only ever be one main-menu window, you can skip the extra property and close everything that isn't the main-menu type:
For Each openWindow As Window In App.Windows()
If Not (openWindow IsA MainMenuWindow) Then
openWindow.Close()
End If
Next
Both are safe to run while iterating because App.Windows() returns a snapshot. As long as the main-menu window is still open (hidden is fine), you'll land back on it; if it can ever be closed before then, re-show it as part of the same routine rather than relying on the reference.