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 保護を無効にします。

Properties

プロパティ データ型 修飾子 説明
BindByDriveLetter Boolean [read, write] ボリュームで使用されるバインディングの種類を示します。
- ボリュームを DriveLetter(loose binding)
- False でバインドする場合は True を指定し、ボリュームを VolumeName (タイト バインディング) でバインドします。
CommitPending Boolean [read] Microsoft 用に予約されています。
CurrentSession Boolean [key, read] オブジェクトに設定が含まれるセッションを示します。
- True の場合、現在のセッション
- の設定は False の場合、再起動後の次のセッションの設定です。
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 は、ボリュームの UWF の保護を有効または無効にする Set-ProtectVolume 関数を作成します。 このスクリプトは、その関数の使用方法を示しています。

$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 スクリプトは 4 つの関数を作成し、それらの使用方法を示します。

最初の関数である Get-FileExclusions は、ボリュームに存在する UWF ファイルの除外リストを表示します。 現在のセッションと再起動後の次のセッションの両方の除外が表示されます。

2 番目の関数である Add-FileExclusion は、指定されたボリュームの UWF 除外リストにファイルまたはフォルダーを追加します。 再起動後の次のセッションで、除外対象が追加されます。

3 番目の関数である Remove-FileExclusion は、指定されたボリュームの UWF 除外リストからファイルまたはフォルダーを削除します。 再起動後の次のセッション用に、除外が削除されます。

4 番目の関数である 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 Pro いいえ
Windows Enterprise はい
Windows Education はい
Windows IoT Enterprise はい