Search code examples
c#navigationbarwindows-explorer

C# - How to prevent expansion of Explorer navigation bar when opened from C# program


When I open windows explorer from c# using the following code the navigation bar keeps expanding to the current folder. I want to stop this.

    var processStartInfo = new ProcessStartInfo(@"C:\Users");
    Process.Start(processStartInfo);

enter image description here


Solution

  • I think you need to modify registry.

    1. Set NavPaneExpandToCurrentFolder to 0
    2. Do whatever you want
    3. Restore existing value of NavPaneExpandToCurrentFolder

    Use following code to modify registry:

    using Microsoft.Win32;
    

     

    const string key = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced";
    int enabled = 1; // 0 to disable
    Registry.SetValue(key, "NavPaneExpandToCurrentFolder", enabled, RegistryValueKind.DWord);