Partilhar via


UWF_Volume

Essa classe gerencia um volume protegido pelo Filtro de Gravação 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 a seguir listam os métodos e as propriedades que pertencem a essa classe.

Métodos

Método Descrição
UWF_Volume.AddExclusion Adiciona um arquivo ou pasta à lista de exclusão de arquivos de um volume protegido pelo UWF.
UWF_Volume.CommitFile Confirma as alterações da sobreposição para o volume físico de um arquivo especificado em um volume protegido pelo Filtro de Gravação Unificado (UWF).
UWF_Volume.CommitFileDeletion Exclui um arquivo protegido do volume e confirma a exclusão para o volume físico.
UWF_Volume.FindExclusion Determina se um arquivo ou pasta específica está na lista de exclusão de um volume protegido pelo UWF.
UWF_Volume.GetExclusions Recupera uma lista de todas as exclusões de arquivo de um volume protegido pelo UWF.
UWF_Volume.Proteger Protege o volume após a próxima reinicialização do sistema, se o UWF estiver habilitado após a reinicialização.
UWF_Volume.RemoveAllExclusions Remove todos os arquivos e pastas da lista de exclusão de arquivos de um volume protegido por UWF.
UWF_Volume.RemoveExclusion Remove um arquivo ou pasta específica da lista de exclusão de arquivos de um volume protegido pelo UWF.
UWF_Volume.SetBindByDriveLetter Define a propriedade BindByDriveLetter , que indica se o volume UWF está vinculado ao volume físico por letra de unidade ou por nome de volume.
UWF_Volume.Desproteger Desativa a proteção UWF do volume após a próxima reinicialização do sistema.

Propriedades

Propriedade Tipo de dados Qualificadores Descrição
BindByDriveLetter Booliano [ler, escrever] Indica o tipo de associação que o volume usa.
- True para vincular o volume por DriveLetter(associação solta)-
False
para vincular o volume por VolumeName (vinculação apertada).
CommitPending Booliano [read] Reservado para uso da Microsoft.
CurrentSession Booliano [chave, ler] Indica para qual sessão o objeto contém configurações.
- True se as configurações forem para a sessão
- atual False
se as configurações forem para a próxima sessão que se segue a uma reinicialização.
DriveLetter string [chave, ler] A letra da unidade do volume. Se o volume não tiver uma letra de unidade, esse valor será NULL.
Protegido Booliano [ler, escrever] Se CurrentSession for true, indica se o volume está atualmente protegido pela UWF.
Se CurrentSession for false, indica se o volume está protegido na próxima sessão após a reinicialização do dispositivo.
Nome do volume string [chave, ler] 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

Você deve usar 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 a seguir demonstra como proteger ou desproteger um volume com UWF usando o provedor WMI (Instrumentação de Gerenciamento do Windows) em um 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 usar 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

Gerenciar exclusões de arquivos e pastas UWF

O exemplo a seguir demonstra como gerenciar exclusões de arquivos e pastas UWF usando o provedor WMI em um script do PowerShell. O script do PowerShell cria quatro funções e, em seguida, demonstra como usá-las.

A primeira função, Get-FileExclusions, exibe uma lista de exclusões de arquivo UWF que existem em um volume. As exclusões para a sessão atual e a próxima sessão que se segue a uma reinicialização são exibidas.

A segunda função, Add-FileExclusion, adiciona um arquivo 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 uma reinicialização.

A terceira função, Remove-FileExclusion, remove um arquivo 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 uma reinicialização.

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

$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
Educação do Windows Sim
Windows IoT Enterprise Yes