检查文件或文件夹是否为 "Always available offline"?
Check if file or folder is "Always available offline"?
我们如何检查(return 真或假)文件夹或文件是否为 "Always available offline" 激活?我正在使用 Microsoft 同步中心。
我能够通过使用 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"]
}
}
}
我们如何检查(return 真或假)文件夹或文件是否为 "Always available offline" 激活?我正在使用 Microsoft 同步中心。
我能够通过使用 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"]
}
}
}