UWF_Volume

Esta clase administra un volumen protegido por el filtro de escritura unificado (UWF).

Sintaxis

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

};

Members

En las tablas siguientes se enumeran los métodos y las propiedades que pertenecen a esta clase.

Métodos

Método Descripción
UWF_Volume.AddExclusion Agrega un archivo o carpeta a la lista de exclusión de archivos para un volumen protegido porUWF.
UWF_Volume.CommitFile Confirma los cambios de la superposición en el volumen físico de un archivo especificado en un volumen protegido por el filtro de escritura unificado (UWF).
UWF_Volume.CommitFileDeletion Elimina un archivo protegido del volumen y confirma la eliminación en el volumen físico.
UWF_Volume.FindExclusion Determina si un archivo o carpeta específico está en la lista de exclusión de un volumen protegido porUWF.
UWF_Volume.GetExclusions Recupera una lista de todas las exclusiones de archivos para un volumen protegido porUWF.
UWF_Volume.Protect Protege el volumen después del siguiente reinicio del sistema, si UWF está habilitado después del reinicio.
UWF_Volume.RemoveAllExclusions Quita todos los archivos y carpetas de la lista de exclusión de archivos de un volumen protegido por UWF.
UWF_Volume.RemoveExclusion Quita un archivo o carpeta específicos de la lista de exclusión de archivos para un volumen protegido porUWF.
UWF_Volume.SetBindByDriveLetter Establece la propiedad BindByDriveLetter , que indica si el volumen UWF está enlazado al volumen físico por letra de unidad o por nombre de volumen.
UWF_Volume.Unprotect Deshabilita la protección UWF del volumen después del siguiente reinicio del sistema.

Propiedades

Propiedad Tipo de datos Calificadores Descripción
BindByDriveLetter Boolean [lectura, escritura] Indica el tipo de enlace que usa el volumen.
- True para enlazar el volumen por DriveLetter(enlace flexible)
- False para enlazar el volumen por VolumeName (enlace ajustado).
CommitPending Boolean [read] Reservado para uso de Microsoft.
CurrentSession Boolean [key, read] Indica la sesión para la que el objeto contiene la configuración.
- True si la configuración es para la sesión
- actualFalse si la configuración es para la siguiente sesión que sigue a un reinicio.
DriveLetter string [key, read] Letra de unidad del volumen. Si el volumen no tiene una letra de unidad, este valor es NULL.
Protegido Boolean [lectura, escritura] Si CurrentSession es true, indica si el volumen está protegido actualmente por UWF.
Si CurrentSession es false, indica si el volumen está protegido en la siguiente sesión después de reiniciar el dispositivo.
VolumeName string [key, read] Identificador único del volumen en el sistema actual. VolumeName es el mismo que la propiedad DeviceID de la clase Win32_Volume para el volumen.

Comentarios

Debe usar una cuenta de administrador para cambiar las propiedades o llamar a cualquier método que cambie las opciones de configuración.

Activar o desactivar la protección UWF

En el ejemplo siguiente se muestra cómo proteger o desproteger un volumen con UWF mediante el proveedor instrumental de administración de Windows (WMI) en un script de PowerShell.

PowerShellscript crea una función , Set-ProtectVolume, que activa o desactiva la protección de UWF para un volumen. A continuación, el script muestra cómo usar la función .

$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

Administrar exclusiones de archivos y carpetas UWF

En el ejemplo siguiente se muestra cómo administrar exclusiones de archivos y carpetas UWF mediante el proveedor WMI en un script de PowerShell. El script de PowerShell crea cuatro funciones y, a continuación, muestra cómo usarlas.

La primera función, Get-FileExclusions, muestra una lista de exclusiones de archivos UWF que existen en un volumen. Se muestran exclusiones para la sesión actual y la siguiente sesión que sigue a un reinicio.

La segunda función Add-FileExclusion agrega un archivo o carpeta a la lista de exclusión de UWF para un volumen determinado. La exclusión se agrega para la siguiente sesión que sigue a un reinicio.

La tercera función , Remove-FileExclusion, quita un archivo o carpeta de la lista de exclusión de UWF para un volumen determinado. La exclusión se quita para la siguiente sesión que sigue a un reinicio.

La cuarta función , Clear-FileExclusions, quita todas las exclusiones de archivos y carpetas de UWF de un volumen determinado. Las exclusiones se quitan para la siguiente sesión que sigue a un reinicio.

$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

Edición de Windows Compatible
Windows Home No
Windows Pro No
Windows Enterprise
Windows Education
Windows IoT Enterprise