UWF_Volume
Questa classe gestisce un volume protetto da UWF (Unified Write Filter).
Sintassi
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[]);
};
Membri
Nelle tabelle seguenti sono elencati i metodi e le proprietà che appartengono a questa classe.
Metodi
Metodo | Descrizione |
---|---|
UWF_Volume.AddExclusion | Aggiunge un file o una cartella all'elenco di esclusione di file per un volume protetto daUWF. |
UWF_Volume.CommitFile | Esegue il commit delle modifiche dalla sovrimpressione al volume fisico per un file specificato in un volume protetto da Unified Write Filter (UWF). |
UWF_Volume.CommitFileDeletion | Elimina un file protetto dal volume ed esegue il commit dell'eliminazione nel volume fisico. |
UWF_Volume.FindExclusion | Determina se un file o una cartella specifica è incluso nell'elenco di esclusione per un volume protetto daUWF. |
UWF_Volume.GetExclusions | Recupera un elenco di tutte le esclusioni di file per un volume protetto daUWF. |
UWF_Volume.Protect | Protegge il volume dopo il successivo riavvio del sistema, se UWF è abilitato dopo il riavvio. |
UWF_Volume.RemoveAllExclusions | Rimuove tutti i file e le cartelle dall'elenco di esclusione di file per un volume protetto da UWF. |
UWF_Volume.RemoveExclusion | Rimuove un file o una cartella specifica dall'elenco di esclusione di file per un volume protetto daUWF. |
UWF_Volume.SetBindByDriveLetter | Imposta la proprietà BindByDriveLetter , che indica se il volume UWF è associato al volume fisico in base alla lettera di unità o al nome del volume. |
UWF_Volume.Unprotect | Disabilita la protezione UWF del volume dopo il successivo riavvio del sistema. |
Proprietà
Proprietà | Tipo di dati | Qualificazioni | Descrizione |
---|---|---|---|
BindByDriveLetter | Booleano | [lettura, scrittura] | Indica il tipo di associazione utilizzato dal volume. - True per associare il volume tramite DriveLetter(binding libero) - False per associare il volume in base a VolumeName (binding stretto). |
CommitPending | Booleano | [lettura] | Riservato per l'uso microsoft. |
CurrentSession | Booleano | [chiave, lettura] | Indica la sessione per cui l'oggetto contiene le impostazioni. - True se le impostazioni sono relative alla sessione - correnteFalse se le impostazioni riguardano la sessione successiva che segue un riavvio. |
DriveLetter | stringa | [chiave, lettura] | Lettera di unità del volume. Se il volume non ha una lettera di unità, questo valore è NULL. |
Protetto | Booleano | [lettura, scrittura] | Se CurrentSession è true, indica se il volume è attualmente protetto da UWF. Se CurrentSession è false, indica se il volume è protetto nella sessione successiva dopo il riavvio del dispositivo. |
VolumeName | stringa | [chiave, lettura] | Identificatore univoco del volume nel sistema corrente. VolumeName corrisponde alla proprietà DeviceID della classe Win32_Volume per il volume. |
Osservazioni
È necessario usare un account amministratore per modificare le proprietà o chiamare i metodi che modificano le impostazioni di configurazione.
Attivare o disattivare la protezione UWF
Nell'esempio seguente viene illustrato come proteggere o rimuovere la protezione di un volume con UWF usando il provider Strumentazione gestione Windows (WMI) in uno script di PowerShell.
PowerShellscript crea una funzione, Set-ProtectVolume, che attiva o disattiva la protezione UWF per un volume. Lo script illustra quindi come usare la funzione .
$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
Gestire le esclusioni di file e cartelle UWF
Nell'esempio seguente viene illustrato come gestire le esclusioni di file e cartelle UWF usando il provider WMI in uno script di PowerShell. Lo script di PowerShell crea quattro funzioni e quindi illustra come usarle.
La prima funzione , Get-FileExclusions, visualizza un elenco di esclusioni di file UWF presenti in un volume. Vengono visualizzate le esclusioni per la sessione corrente e la sessione successiva successiva a un riavvio.
La seconda funzione, Add-FileExclusion, aggiunge un file o una cartella all'elenco di esclusione UWF per un determinato volume. L'esclusione viene aggiunta per la sessione successiva che segue un riavvio.
La terza funzione , Remove-FileExclusion, rimuove un file o una cartella dall'elenco di esclusione UWF per un determinato volume. L'esclusione viene rimossa per la sessione successiva che segue un riavvio.
La quarta funzione , Clear-FileExclusions, rimuove tutte le esclusioni di file E cartelle UWF da un determinato volume. Le esclusioni vengono rimosse per la sessione successiva che segue un riavvio.
$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:"
Requisiti
Edizione di Windows | Supportato |
---|---|
Windows Home | No |
Windows Pro | No |
Windows Enterprise | Sì |
Windows Education | Sì |
Windows IoT Enterprise | Sì |