Share via


UWF_Volume

此類別會管理受 Unified Write Filter (UWF) 保護的磁碟區。

語法

class UWF_Volume {
    [key, Read] boolean CurrentSession;
    [key, Read] string DriveLetter;
    [key, Read] string VolumeName;
    [Read, Write] boolean BindByDriveLetter;
    [Read] boolean CommitPending;
    [Read, Write] boolean Protected;

    UInt32 CommitFile([in] string FileFullPath);
    UInt32 CommitFileDeletion(string FileName);
    UInt32 Protect();
    UInt32 Unprotect();
    UInt32 SetBindByDriveLetter(boolean bBindByVolumeName);
    UInt32 AddExclusion(string FileName);
    UInt32 RemoveExclusion(string FileName);
    UInt32 RemoveAllExclusions();
    UInt32 FindExclusion([in] string FileName, [out] bFound);
    UInt32 GetExclusions([out, EmbeddedInstance("UWF_ExcludedFile")] string ExcludedFiles[]);

};

成員

下表列出屬於這個類別的方法和屬性。

方法

方法 描述
UWF_Volume.AddExclusion 將檔案或資料夾新增至受UWF保護之磁碟區的檔案排除清單。
UWF_Volume.CommitFile 將重迭變更認可到受整合寫入篩選器 (UWF) 保護之磁碟區上指定檔案的實體磁碟區。
UWF_Volume.CommitFileDeletion 從磁碟區中刪除受保護的檔案,並將刪除認可到實體磁碟區。
UWF_Volume.FindExclusion 判斷特定檔案或資料夾是否位於受UWF保護之磁碟區的排除清單中。
UWF_Volume.GetExclusions 擷取受UWF保護之磁碟區的所有檔案排除清單。
UWF_Volume.Protect 如果在重新啟動后啟用 UWF,則保護下一個系統重新啟動之後的磁碟區。
UWF_Volume.RemoveAllExclusions 從 UWF 所保護磁碟區的檔案排除清單中移除所有檔案和資料夾。
UWF_Volume.RemoveExclusion 從受UWF保護之磁碟區的檔案排除清單中移除特定檔案或資料夾。
UWF_Volume.SetBindByDriveLetter 設定 BindByDriveLetter 屬性,指出 UWF 磁碟區是透過驅動器號或磁碟區名稱系結至實體磁碟區。
UWF_Volume.Unprotect 在下一個系統重新啟動之後,停用磁碟區的 UWF 保護。

屬性

屬性 資料類型 限定詞 描述
BindByDriveLetter 布林值 [read, write] 指出磁碟區所使用的系結類型。
- True 是表示 依 DriveLetter 系結磁碟區(鬆散系結)-
False
系結磁碟區,以依 VolumeName 系結磁碟區(緊密系結)。
CommitPending 布林值 [read] 保留給 Microsoft 使用。
CurrentSession 布林值 [key, read] 指出物件包含的設定的會話。
- 如果目前會話
- 的設定為 False
,則為 True
,如果設定是在重新啟動之後的下一個會話。
DriveLetter 字串 [key, read] 磁碟區的驅動器號。 如果磁碟區沒有驅動器號,則此值為 NULL
Protected 布林值 [read, write] 如果 CurrentSessiontrue,表示磁碟區目前是否受到 UWF 的保護。
如果 CurrentSessionfalse,表示磁碟區是否在裝置重新啟動後的下一個會話中受到保護。
VolumeName 字串 [key, read] 目前系統上磁碟區的唯一標識符。 VolumeName磁碟區Win32_Volume類別的 DeviceID 屬性相同。

備註

您必須使用系統管理員帳戶來變更任何屬性,或呼叫任何變更組態設定的方法。

開啟或關閉UWF保護

下列範例示範如何在PowerShell腳本中使用Windows Management Instrumentation (WMI) 提供者來保護或取消保護 UWF 的磁碟區。

PowerShellscript 會建立函 式 Set-ProtectVolume,以開啟或關閉磁碟區的 UWF 保護。 然後腳本會示範如何使用 函式。

$COMPUTER = "localhost"
$NAMESPACE = "root\standardcimv2\embedded"

# Define common parameters

$CommonParams = @{"namespace"=$NAMESPACE; "computer"=$COMPUTER}

# Create a function to protect or unprotect a volume based on the drive letter of the volume

function Set-ProtectVolume($driveLetter, [bool] $enabled) {

# Each volume has two entries in UWF_Volume, one for the current session and one for the next session after a restart
# You can only change the protection status of a drive for the next session

    $nextConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $false
        };

# If a volume entry is found for the drive letter, enable or disable protection based on the $enabled parameter

    if ($nextConfig) {

        Write-Host "Setting drive protection on $driveLetter to $enabled"

        if ($Enabled -eq $true) {
            $nextConfig.Protect() | Out-Null;
        } else {
            $nextConfig.Unprotect() | Out-Null;
        }
    }

# If the drive letter does not match a volume, create a new UWF_volume instance

    else {
    Write-Host "Error: Could not find $driveLetter. Protection is not enabled."
    }
}

# The following sample commands demonstrate how to use the Set-ProtectVolume function
# to protect and unprotect volumes

Set-ProtectVolume "C:" $true
Set-ProtectVolume "D:" $true

Set-ProtectVolume "C:" $false

管理 UWF 檔案和資料夾排除專案

下列範例示範如何在PowerShell腳本中使用WMI提供者來管理UWF檔案和資料夾排除專案。 PowerShell 腳本會建立四個函式,然後示範如何使用它們。

第一個函 式 Get-FileExclusions 會顯示磁碟區上存在的 UWF 檔案排除清單。 會顯示目前會話和下一個重新啟動後會話的排除專案。

第二個函式 Add-FileExclusion 會將檔案或資料夾新增至指定磁碟區的 UWF 排除清單。 在重新啟動之後的下一個會話中,會新增排除專案。

第三個函式 Remove-FileExclusion 會從指定磁碟區的 UWF 排除列表中移除檔案或資料夾。 重新啟動之後的下一個會話會移除排除專案。

第四個函 式 Clear-FileExclusions 會移除指定磁碟區中的所有 UWF 檔案和資料夾排除專案。 下一個重新啟動之後的會話會移除排除專案。

$COMPUTER = "localhost"
$NAMESPACE = "root\standardcimv2\embedded"

# Define common parameters

$CommonParams = @{"namespace"=$NAMESPACE; "computer"=$COMPUTER}

function Get-FileExclusions($driveLetter) {

# This function lists the UWF file exclusions for a volume, both
# for the current session as well as the next session after a restart 

# $driveLetter is the drive letter of the volume

# Get the UWF_Volume configuration for the current session

    $currentConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $true
        };

# Get the UWF_Volume configuration for the next session after a restart

    $nextConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $false
        };

# Display file exclusions for the current session

    if ($currentConfig) {

        Write-Host "The following files and folders are currently excluded from UWF filtering for $driveLetter";

        $currentExcludedList = $currentConfig.GetExclusions()

        if ($currentExcludedList) {
            foreach ($fileExclusion in $currentExcludedList.ExcludedFiles)  {
                Write-Host "  " $fileExclusion.FileName
            }
        } else {
            Write-Host "  None"
        }
    } else {
        Write-Error "Could not find drive $driveLetter";
}

# Display file exclusions for the next session after a restart

    if ($nextConfig) {

        Write-Host ""
        Write-Host "The following files and folders will be excluded from UWF filtering for $driveLetter after the next restart:";

        $nextExcludedList = $nextConfig.GetExclusions()

        if ($nextExcludedList) {
            foreach ($fileExclusion in $nextExcludedList.ExcludedFiles)  {
                Write-Host "  " $fileExclusion.FileName
            }
        } else {
            Write-Host "  None"
        }

        Write-Host ""
    }
}

function Add-FileExclusion($driveLetter, $exclusion) {

# This function adds a new UWF file exclusion to a volume
# The new file exclusion takes effect the next time the device is restarted and UWF is enabled

# $driveLetter is the drive letter of the volume
# $exclusion is the path and filename of the file or folder exclusion

# Get the configuration for the next session for the volume

    $nextConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $false
        };

# Add the exclusion

    if ($nextConfig) {
        $nextConfig.AddExclusion($exclusion) | Out-Null;
        Write-Host "Added exclusion $exclusion for $driveLetter";
    } else {
        Write-Error "Could not find drive $driveLetter";
    }
}

function Remove-FileExclusion($driveLetter, $exclusion) {

# This function removes a UWF file exclusion from a volume
# The file exclusion is removed the next time the device is restarted

# $driveLetter is the drive letter of the volume
# $exclusion is the path and filename of the file or folder exclusion

# Get the configuration for the next session for the volume

    $nextConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $false
        };

# Try to remove the exclusion

    if ($nextConfig) {
        try {
            $nextConfig.RemoveExclusion($exclusion) | Out-Null;
            Write-Host "Removed exclusion $exclusion for $driveLetter";
        } catch {
            Write-Host "Could not remove exclusion $exclusion on drive $driveLetter"
        }
    } else {
        Write-Error "Could not find drive $driveLetter";
    }
}

function Clear-FileExclusions($driveLetter) {

# This function removes all UWF file exclusions on a volume
# The file exclusions are removed the next time the device is restarted

# $driveLetter is the drive letter of the volume

# Get the configuration for the next session for the volume

    $nextConfig = Get-WMIObject -class UWF_Volume @CommonParams |
        where {
            $_.DriveLetter -eq "$driveLetter" -and $_.CurrentSession -eq $false
        };

# Remove all file and folder exclusions

    if ($nextConfig) {
        $nextConfig.RemoveAllExclusions() | Out-Null;
        Write-Host "Cleared all exclusions for $driveLetter";
    } else {
        Write-Error "Could not clear exclusions for drive $driveLetter";
    }
}

# Some examples of using the functions

Clear-FileExclusions "C:"

Add-FileExclusion "C:" "\Users\Public\Public Documents"
Add-FileExclusion "C:" "\myfolder\myfile.txt"

Get-FileExclusions "C:"

Remove-FileExclusion "C:" "\myfolder\myfile.txt"

Get-FileExclusions "C:"

需求

Windows 版本 支援
Windows Home No
Windows 專業版 No
Windows 企業版 Yes
Windows 教育版 Yes
Windows IoT 企業版 Yes