Refresh Windows Explorer in Win7

前端 未结 4 1330
野性不改
野性不改 2020-12-09 04:13

My program sets \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced\" value \"Hidden\". Hovewer I\'m not able to refresh the e

相关标签:
4条回答
  • 2020-12-09 04:38

    With Windows 10 having changed the name of the Explorer window:

    if ((itemName == "Windows Explorer") || (itemName == "File Explorer")) {
        itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, null, item, null);
    }
    
    0 讨论(0)
  • 2020-12-09 04:43

    I figured out a way to check if the windows was a Windows Explorer window, and don't have enough of a rep to add a comment so thought I'd submit it as an answer to help you out because this question helped me out.

            // based on http://stackoverflow.com/questions/2488727/refresh-windows-explorer-in-win7
            Guid CLSID_ShellApplication = new Guid("13709620-C279-11CE-A49E-444553540000");
            Type shellApplicationType = Type.GetTypeFromCLSID(CLSID_ShellApplication, true);
    
            object shellApplication = Activator.CreateInstance(shellApplicationType);
            object windows = shellApplicationType.InvokeMember("Windows", System.Reflection.BindingFlags.InvokeMethod, null, shellApplication, new object[] { });
    
            Type windowsType = windows.GetType();
            object count = windowsType.InvokeMember("Count", System.Reflection.BindingFlags.GetProperty, null, windows, null);
            for (int i = 0; i < (int)count; i++)
            {
                object item = windowsType.InvokeMember("Item", System.Reflection.BindingFlags.InvokeMethod, null, windows, new object[] { i });
                Type itemType = item.GetType();
    
                // only refresh windows explorers
                string itemName = (string)itemType.InvokeMember("Name", System.Reflection.BindingFlags.GetProperty, null, item, null);
                if (itemName == "Windows Explorer")
                {
                    itemType.InvokeMember("Refresh", System.Reflection.BindingFlags.InvokeMethod, null, item, null);
                }
            }
    
    0 讨论(0)
  • 2020-12-09 04:59

    I don't know about Open/Save dialogs, but you can get a list of open explorer windows with COM automation, the Shell.Application object has a collection of windows, or CoCreate IID_IShellWindows directly, each window in the list has a refresh method.

    WSH/JScript:

    for(var sw=new ActiveXObject("Shell.Application").Windows(),i=0;i<sw.Count; ++i)
       sw.Item(i).Refresh();
    

    I don't know about C#, but here are examples dealing with shell windows in WSH/JScript and c++

    0 讨论(0)
  • 2020-12-09 05:01

    When you install an application that registers a file type, Explorer windows often refresh to indicate the new association - could you spy on the API calls that an installer is making to see how it refreshes the window?

    0 讨论(0)
提交回复
热议问题