FileRevocationManager.ProtectAsync(IStorageItem, String) 方法

定義

注意

從 2022 年 7 月開始,Microsoft 即將淘汰 Windows 資訊保護 (WIP) 和支援 WIP 的 API。 Microsoft 將繼續在支援的 Windows 版本上支援 WIP。 新版本的 Windows 不會包含 WIP 的新功能,而且未來版本的 Windows 不支援此功能。 如需詳細資訊,請參閱宣佈 Windows 資訊保護終止

針對資料保護需求,Microsoft 建議您使用Microsoft Purview 資訊保護Microsoft Purview 資料外洩防護。 Purview 可簡化組態設定,並提供一組進階功能。

注意

Windows 10之後,FileRevocationManager可能無法用於發行。 請改 用 FileProtectionManager

保護檔案或資料夾以進行選擇性抹除。

public:
 static IAsyncOperation<FileProtectionStatus> ^ ProtectAsync(IStorageItem ^ storageItem, Platform::String ^ enterpriseIdentity);
/// [Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.Security.EnterpriseData.EnterpriseDataContract)]
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<FileProtectionStatus> ProtectAsync(IStorageItem const& storageItem, winrt::hstring const& enterpriseIdentity);
/// [Windows.Foundation.Metadata.RemoteAsync]
/// [Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Security.EnterpriseData.EnterpriseDataContract")]
 static IAsyncOperation<FileProtectionStatus> ProtectAsync(IStorageItem const& storageItem, winrt::hstring const& enterpriseIdentity);
[Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.Security.EnterpriseData.EnterpriseDataContract))]
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<FileProtectionStatus> ProtectAsync(IStorageItem storageItem, string enterpriseIdentity);
[Windows.Foundation.Metadata.RemoteAsync]
[Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Security.EnterpriseData.EnterpriseDataContract")]
public static IAsyncOperation<FileProtectionStatus> ProtectAsync(IStorageItem storageItem, string enterpriseIdentity);
function protectAsync(storageItem, enterpriseIdentity)
Public Shared Function ProtectAsync (storageItem As IStorageItem, enterpriseIdentity As String) As IAsyncOperation(Of FileProtectionStatus)

參數

storageItem
IStorageItem

要保護以進行選擇性抹除的檔案或資料夾。

enterpriseIdentity
String

Platform::String

winrt::hstring

檔案或資料夾受到保護的企業識別碼。 enterpriseIdentity值必須格式化為國際化功能變數名稱 (IDN) ,且不能包含空格。 例如:contoso.com

傳回

非同步作業,擷取 storageItem的選擇性抹除保護狀態。

屬性

備註

您可以使用 ProtectAsync 方法來使用選擇性抹除來保護檔案或資料夾。 這會將檔案識別為您的企業識別碼保護,例如 「example.com」,如上一個程式碼範例所示。 如果您使用 ProtectAsync 方法來保護資料夾,則該資料夾中的所有檔案都會繼承相同的保護。

ApplicationData appRootFolder = ApplicationData.Current;
string enterpriseIdentity = "example.com";
int AccessDeniedHResult = -2147024891;  // Access Denied (0x80070005)
// Add a folder and protect it using Selective Wipe.
private async Task<StorageFolder> AddFolder(string folderName)
{
    StorageFolder newFolder = await appRootFolder.LocalFolder.CreateFolderAsync(folderName);

    var status = await ProtectItem(newFolder, enterpriseIdentity);

    return newFolder;
}

// Add a file and protect it using Selective Wipe.
private async Task<StorageFile> AddFile(string fileName, StorageFolder folder)
{
    StorageFile newFile = await folder.CreateFileAsync(fileName);

    var status = 
        await Windows.Security.EnterpriseData.FileRevocationManager.
            GetStatusAsync(newFile);

    if (status != Windows.Security.EnterpriseData.FileProtectionStatus.Protected)
    {
        status = await ProtectItem(newFile, enterpriseIdentity);
    }

    return newFile;
}

private async Task<Windows.Security.EnterpriseData.FileProtectionStatus> 
    ProtectItem(IStorageItem item, string enterpriseIdentity)
{
    var status = 
        await Windows.Security.EnterpriseData.FileRevocationManager.
            ProtectAsync(item, enterpriseIdentity);

    return status;
}

ProtectAsync 方法需要對加密的檔案或資料夾進行獨佔存取,如果另一個進程正在使用的檔案或資料夾有開啟的控制碼,將會失敗。

適用於

另請參閱