检查文件或文件夹是否为“始终可脱机使用”?

时间:2018-12-04 11:56:46

标签: c# .net windows-10 offline-caching

我们如何检查(返回true或false)是否为“始终可用离线”激活了文件夹或文件?我正在使用Microsoft同步中心。

enter image description here

1 个答案:

答案 0 :(得分:1)

我能够通过使用WMI提供程序来获得需要的信息: https://docs.microsoft.com/de-de/previous-versions/windows/desktop/offlinefiles/about-offline-files-wmi-provider

编辑:

别忘了添加对System.Management的引用。

我想出了以下代码段:

            ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");
            ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_OfflineFilesItem");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection queryCollection = searcher.Get();
            foreach (ManagementObject m in queryCollection)
            {
                var pinInfo = (ManagementBaseObject)m.GetPropertyValue("PinInfo");

                if (pinInfo != null)
                {
                    if ((bool)pinInfo.GetPropertyValue("Pinned"))
                    {
                          //the file or folder is set to "always available offline"
                          var itemPath = m["ItemPath"]
                    }
                }
            }