Partilhar via


UWF_Volume

Esta classe gere um volume protegido pelo Filtro de Escrita Unificado (UWF).

Sintaxe

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[]);

};

Membros

As tabelas seguintes listam os métodos e propriedades que pertencem a esta classe.

Métodos

Método Descrição
UWF_Volume.AddExclusion Adiciona um ficheiro ou pasta à lista de exclusão de ficheiros para um volume protegido porUWF.
UWF_Volume.CommitFile Consolida as alterações da sobreposição para o volume físico de um ficheiro especificado num volume protegido pelo Filtro de Escrita Unificado (UWF).
UWF_Volume.CommitFileDeletion Elimina um ficheiro protegido do volume e consolida a eliminação no volume físico.
UWF_Volume.FindExclusion Determina se um ficheiro ou pasta específico está na lista de exclusão de um volume protegido porUWF.
UWF_Volume.GetExclusions Obtém uma lista de todas as exclusões de ficheiros para um volume protegido porUWF.
UWF_Volume.Protect Protege o volume após o reinício do sistema seguinte, se o UWF estiver ativado após o reinício.
UWF_Volume.RemoveAllExclusions Remove todos os ficheiros e pastas da lista de exclusão de ficheiros de um volume protegido pelo UWF.
UWF_Volume.RemoveExclusion Remove um ficheiro ou pasta específico da lista de exclusão de ficheiros para um volume protegido porUWF.
UWF_Volume.SetBindByDriveLetter Define a propriedade BindByDriveLetter , que indica se o volume UWF está vinculado ao volume físico por letra da unidade ou pelo nome do volume.
UWF_Volume.Unprotect Desativa a proteção UWF do volume após o reinício do sistema seguinte.

Propriedades

Propriedade Tipo de dados Qualificadores Descrição
BindByDriveLetter Booliano [ler, escrever] Indica o tipo de enlace que o volume utiliza.
- Verdadeiro para vincular o volume por DriveLetter(enlace solto)
- Falso para vincular o volume por VolumeName (enlace apertado).
CommitPending Booliano [ler] Reservado para utilização da Microsoft.
CurrentSession Booliano [chave, leitura] Indica para que sessão o objeto contém definições.
- Verdadeiro se as definições forem para a sessão
- atualFalso se as definições forem para a próxima sessão que se segue a um reinício.
DriveLetter string [chave, leitura] A letra de unidade do volume. Se o volume não tiver uma letra de unidade, este valor é NULO.
Protegido Booliano [ler, escrever] Se CurrentSession for verdadeiro, indica se o volume está atualmente protegido pelo UWF.
Se CurrentSession for falso, indica se o volume está protegido na próxima sessão após o dispositivo reiniciar.
VolumeName string [chave, leitura] O identificador exclusivo do volume no sistema atual. O VolumeName é o mesmo que a propriedade DeviceID da classe Win32_Volume para o volume.

Comentários

Tem de utilizar uma conta de administrador para alterar quaisquer propriedades ou chamar quaisquer métodos que alterem as definições de configuração.

Ativar ou desativar a proteção UWF

O exemplo seguinte demonstra como proteger ou desproteger um volume com UWF através do fornecedor do Windows Management Instrumentation (WMI) num script do PowerShell.

O PowerShellscript cria uma função, Set-ProtectVolume, que ativa ou desativa a proteção UWF para um volume. Em seguida, o script demonstra como utilizar a função.

$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

Gerir exclusões de ficheiros e pastas UWF

O exemplo seguinte demonstra como gerir exclusões de ficheiros e pastas UWF com o fornecedor WMI num script do PowerShell. O script do PowerShell cria quatro funções e, em seguida, demonstra como utilizá-las.

A primeira função, Get-FileExclusions, apresenta uma lista de exclusões de ficheiros UWF que existem num volume. São apresentadas exclusões para a sessão atual e para a sessão seguinte que se segue a um reinício.

A segunda função, Add-FileExclusion, adiciona um ficheiro ou pasta à lista de exclusão UWF para um determinado volume. A exclusão é adicionada para a próxima sessão que se segue a um reinício.

A terceira função, Remove-FileExclusion, remove um ficheiro ou pasta da lista de exclusão UWF para um determinado volume. A exclusão é removida para a próxima sessão que se segue a um reinício.

A quarta função , Clear-FileExclusions, remove todas as exclusões de ficheiros e pastas UWF de um determinado volume. As exclusões são removidas para a próxima sessão que se segue a um reinício.

$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:"

Requisitos

Edição do Windows Com suporte
Windows Home Não
Windows Pro Não
Windows Enterprise Sim
Windows Education Sim
Windows IoT Enterprise Sim