UWF_Volume

Cette classe gère un volume protégé par un filtre d’écriture unifié (UWF).

Syntaxe

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

};

Membres

Les tableaux suivants répertorient les méthodes et les propriétés qui appartiennent à cette classe.

Méthodes

Méthode Description
UWF_Volume.AddExclusion Ajoute un fichier ou un dossier à la liste d’exclusions de fichiers pour un volume protégé parUWF.
UWF_Volume.CommitFile Valide les modifications de la superposition vers le volume physique pour un fichier spécifié sur un volume protégé par le filtre d’écriture unifié (UWF).
UWF_Volume.CommitFileDeletion Supprime un fichier protégé du volume et valide la suppression sur le volume physique.
UWF_Volume.FindExclusion Détermine si un fichier ou un dossier spécifique figure dans la liste d’exclusions pour un volume protégé parUWF.
UWF_Volume.GetExclusions Récupère la liste de toutes les exclusions de fichiers pour un volume protégé parUWF.
UWF_Volume.Protect Protège le volume après le redémarrage suivant du système, si UWF est activé après le redémarrage.
UWF_Volume.RemoveAllExclusions Supprime tous les fichiers et dossiers de la liste d’exclusion de fichiers pour un volume protégé par UWF.
UWF_Volume.RemoveExclusion Supprime un fichier ou un dossier spécifique de la liste d’exclusions de fichiers pour un volume protégé parUWF.
UWF_Volume.SetBindByDriveLetter Définit la propriété BindByDriveLetter , qui indique si le volume UWF est lié au volume physique par lettre de lecteur ou par nom de volume.
UWF_Volume.Unprotect Désactive la protection UWF du volume après le prochain redémarrage du système.

Propriétés

Propriété Type de données Qualificateurs Description
BindByDriveLetter Booléen [lecture, écriture] Indique le type de liaison utilisé par le volume.
- True pour lier le volume par DriveLetter(liaison libre)
- False pour lier le volume par VolumeName (liaison étroite).
CommitPending Boolean [Lecture] Réservé à l’utilisation de Microsoft.
CurrentSession Booléen [key, read] Indique la session pour laquelle l’objet contient des paramètres.
- True si les paramètres sont pour la session
- activeFalse si les paramètres sont pour la session suivante qui suit un redémarrage.
DriveLetter chaîne [key, read] Lettre de lecteur du volume. Si le volume n’a pas de lettre de lecteur, cette valeur est NULL.
Protected Boolean [lecture, écriture] Si CurrentSession a lavaleur true, indique si le volume est actuellement protégé par UWF.
Si CurrentSession a la valeur false, indique si le volume est protégé lors de la session suivante après le redémarrage de l’appareil.
VolumeName chaîne [key, read] Identificateur unique du volume sur le système actuel. VolumeName est identique à la propriété DeviceID de la classe Win32_Volume pour le volume.

Remarques

Vous devez utiliser un compte d’administrateur pour modifier les propriétés ou appeler des méthodes qui modifient les paramètres de configuration.

Activer ou désactiver la protection UWF

L’exemple suivant montre comment protéger ou annuler la protection d’un volume avec UWF à l’aide du fournisseur WMI (Windows Management Instrumentation) dans un script PowerShell.

PowerShellscript crée une fonction, Set-ProtectVolume, qui active ou désactive la protection UWF pour un volume. Le script montre ensuite comment utiliser la fonction .

$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

Gérer les exclusions de fichiers et de dossiers UWF

L’exemple suivant montre comment gérer les exclusions de fichiers et de dossiers UWF à l’aide du fournisseur WMI dans un script PowerShell. Le script PowerShell crée quatre fonctions, puis montre comment les utiliser.

La première fonction, Get-FileExclusions, affiche la liste des exclusions de fichiers UWF qui existent sur un volume. Les exclusions pour la session active et la session suivante qui suit un redémarrage s’affichent.

La deuxième fonction, Add-FileExclusion, ajoute un fichier ou un dossier à la liste d’exclusionS UWF pour un volume donné. L’exclusion est ajoutée pour la session suivante qui suit un redémarrage.

La troisième fonction, Remove-FileExclusion, supprime un fichier ou un dossier de la liste d’exclusionS UWF pour un volume donné. L’exclusion est supprimée pour la session suivante qui suit un redémarrage.

La quatrième fonction, Clear-FileExclusions, supprime toutes les exclusions de fichiers et de dossiers UWF d’un volume donné. Les exclusions sont supprimées pour la session suivante qui suit un redémarrage.

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

Configuration requise

Édition Windows Prise en charge
Windows Famille Non
Windows Professionnel Non
Windows Entreprise Oui
Windows Éducation Oui
Windows IoT Entreprise Oui