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] 指出物件包含設定的會話。
- 如果目前會話
- 的設定為False,則為 True 是表示 如果設定是針對後續重新開機的下一個會話。
DriveLetter string [key, read] 磁片區的磁碟機號。 如果磁片區沒有磁碟機號,則此值為 Null
Protected Boolean [read, write] 如果 CurrentSessiontrue,表示磁片區目前是否受到 UWF 保護。
如果 CurrentSessionfalse,表示磁片區是否在裝置重新開機後於下一個會話中受到保護。
VolumeName string [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 首頁 No
Windows 專業版
Windows 企業版
Windows 教育版
Windows IoT 企業版 是的