UWF_Volume

此类管理受统一写入筛选器 (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 Boolean [read, write] 指示卷使用的绑定类型。
- 如果为 True ,则通过 DriveLetter 绑定 (松散绑定)
- False 通过 VolumeName 绑定卷 (紧密绑定) 。
CommitPending Boolean [read] 保留供 Microsoft 使用。
CurrentSession Boolean [key, read] 指示对象包含设置的会话。
- 如果设置适用于当前会话
- ,则为True 如果设置适用于重启后的下一个会话,则为 False。
DriveLetter string [key, read] 卷的驱动器号。 如果卷没有驱动器号,则此值为 NULL。
受保护 Boolean [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 主页
Windows 专业版
Windows 企业版
Windows 教育版
Windows IoT 企业版 是的