简体   繁体   English

如何获取开放资源管理器窗口的PIDL?

[英]How to get the PIDL of an open explorer window?

I know how to get all open explorer windows , using Microsoft Internet Controls COM library. 我知道如何使用Microsoft Internet Controls COM库获取所有打开的资源管理器窗口 From this, I am able to find the LocationURL of those windows. 从这里,我能够找到那些窗口的LocationURL However, this is only set for paths on the file system. 但是,这仅针对文件系统上的路径设置。 Seemingly when virtual objects are displayed, like network printers or the recycle bin, LocationURL is empty. 看似何时显示虚拟对象 ,如网络打印机或回收站, LocationURL为空。 LocationName still seems to be set to the name which is visible on the start bar. LocationName似乎仍设置为在开始栏上可见的名称。

When LocationURL is set, this is sufficient for my purposes to know where the explorer window is pointing to, but how can I find out what it is pointing to for these special folders? 当设置LocationURL ,这足以让我知道资源管理器窗口指向的位置,但是如何找到它们指向这些特殊文件夹的内容?

Reading up a bit on pointers to an item identifier list (PIDL) . 读取指向项目标识符列表(PIDL)的指针 Knowing which PIDL is being shown in the explorer window could identify that. 知道在资源管理器窗口中显示哪个PIDL可以识别出这一点。 Is there any way to retrieve this? 有没有办法检索这个?

Here is a sample C# Console app code that gets the PIDL of current Windows explorer windows: 下面是一个示例C#Console应用程序代码,它获取当前Windows资源管理器窗口的PIDL:

class Program
{
    static void Main(string[] args)
    {
        var shellWindows = new ShellWindows();
        foreach (IWebBrowser2 win in shellWindows)
        {
            IServiceProvider sp = win as IServiceProvider;
            object sb;
            sp.QueryService(SID_STopLevelBrowser, typeof(IShellBrowser).GUID, out sb);
            IShellBrowser shellBrowser = (IShellBrowser)sb;
            object sv;
            shellBrowser.QueryActiveShellView(out sv);
            Console.WriteLine(win.LocationURL + " " + win.LocationName);
            IFolderView fv = sv as IFolderView;
            if (fv != null)
            {
                // only folder implementation support this (IE windows do not for example)
                object pf;
                fv.GetFolder(typeof(IPersistFolder2).GUID, out pf);
                IPersistFolder2 persistFolder = (IPersistFolder2)pf;

                // get folder class, for example
                // CLSID_ShellFSFolder for standard explorer folders
                Guid clsid;
                persistFolder.GetClassID(out clsid);
                Console.WriteLine(" clsid:" + clsid);

                // get current folder pidl
                IntPtr pidl;
                persistFolder.GetCurFolder(out pidl);

                // TODO: do something with pidl

                Marshal.FreeCoTaskMem(pidl); // free pidl's allocated memory
            }
        }
    }

    internal static readonly Guid SID_STopLevelBrowser = new Guid(0x4C96BE40, 0x915C, 0x11CF, 0x99, 0xD3, 0x00, 0xAA, 0x00, 0x4A, 0xE8, 0x37);

    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("6D5140C1-7436-11CE-8034-00AA006009FA")]
    internal interface IServiceProvider
    {
        void QueryService([MarshalAs(UnmanagedType.LPStruct)] Guid guidService, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppvObject);
    }

    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("1AC3D9F0-175C-11d1-95BE-00609797EA4F")]
    internal interface IPersistFolder2
    {
        void GetClassID(out Guid pClassID);
        void Initialize(IntPtr pidl);
        void GetCurFolder(out IntPtr pidl);
    }

    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214E2-0000-0000-C000-000000000046")]
    internal interface IShellBrowser
    {
        void _VtblGap0_12(); // skip 12 members
        void QueryActiveShellView([MarshalAs(UnmanagedType.IUnknown)] out object ppshv);
        // the rest is not defined
    }

    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")]
    internal interface IFolderView
    {
        void _VtblGap0_2(); // skip 2 members
        void GetFolder([MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object ppv);
        // the rest is not defined
    }
}

Note: Shell interfaces are only partially defined as we don't need the full details. 注意:Shell接口仅部分定义,因为我们不需要完整的详细信息。 Feel free to complete it if you need other information. 如果您需要其他信息,请随时填写。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取要在RegisterChangeNotify中使用的任何文件夹的PIDL - How to get the PIDL of any folder to use in RegisterChangeNotify 如何在列表视图控件中打开列表视图窗口资源管理器 - how to open listview window explorer in listview control 如何使用RichTextBox使用获取目录路径db打开Window Explorer? - How do I use RichTextBox to open Window Explorer with get directory path, db? 在C#中打开的资源管理器窗口中获取文件/目录列表 - Get a list of files/directories in an open Explorer window in C# 打开资源管理器 window 并等待它关闭 - Open explorer window and wait for it to close 如何打开Internet Explorer窗口,在URL上导航并使用c#和mshtml库获取她的文档(HTMLDocument或InternetExplorer) - How open internet explorer window, navigate it on url and get her document(HTMLDocument or InternetExplorer) using c# and mshtml library 打开文件已在窗口浏览器中打开 - Open File Which is already open in window explorer 在GetOpenFileName对话框中获取项目的PIDL - Get PIDL's of items in GetOpenFileName dialog 如何获取打开的窗口的ID,然后调整打开的窗口的大小 - How to get open window's ID and then resize that open window 如何在C#的Windows资源管理器窗口中获取所选文件? - How to get selected file in Windows Explorer window in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM