UWF_Volume

Kelas ini mengelola volume yang dilindungi oleh Unified Write Filter (UWF).

Sintaks

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

};

Anggota

Tabel berikut mencantumkan metode dan properti yang termasuk dalam kelas ini.

Metode

Metode Deskripsi
UWF_Volume.AddExclusion Menambahkan file atau folder ke daftar pengecualian file untuk volume yang dilindungi olehUWF.
UWF_Volume.CommitFile Menerapkan perubahan dari overlay ke volume fisik untuk file tertentu pada volume yang dilindungi oleh Filter Tulis Terpadu (UWF).
UWF_Volume.CommitFileDeletion Menghapus file yang dilindungi dari volume, dan menerapkan penghapusan ke volume fisik.
UWF_Volume.FindExclusion Menentukan apakah file atau folder tertentu berada dalam daftar pengecualian untuk volume yang dilindungi olehUWF.
UWF_Volume.GetExclusions Mengambil daftar semua pengecualian file untuk volume yang dilindungi olehUWF.
UWF_Volume.Protect Melindungi volume setelah sistem berikutnya dimulai ulang, jika UWF diaktifkan setelah hidupkan ulang.
UWF_Volume.RemoveAllExclusions Menghapus semua file dan folder dari daftar pengecualian file untuk volume yang dilindungi oleh UWF.
UWF_Volume.RemoveExclusion Menghapus file atau folder tertentu dari daftar pengecualian file untuk volume yang dilindungi olehUWF.
UWF_Volume.SetBindByDriveLetter Mengatur properti BindByDriveLetter , yang menunjukkan apakah volume UWF terikat ke volume fisik berdasarkan huruf drive atau berdasarkan nama volume.
UWF_Volume.Unprotect Menonaktifkan perlindungan UWF volume setelah sistem berikutnya dimulai ulang.

Properti

Properti Jenis Data Kualifikasi Deskripsi
BindByDriveLetter Boolean [baca, tulis] Menunjukkan jenis pengikatan yang digunakan volume.
- True untuk mengikat volume oleh DriveLetter(pengikatan longgar)
- False untuk mengikat volume dengan VolumeName (pengikatan ketat).
CommitPending Boolean [baca] Dicadangkan untuk penggunaan Microsoft.
CurrentSession Boolean [kunci, baca] Menunjukkan sesi mana objek berisi pengaturan.
- Benar jika pengaturan adalah untuk sesi
- saat iniFalse jika pengaturan adalah untuk sesi berikutnya yang mengikuti mulai ulang.
DriveLetter string [kunci, baca] Huruf kandar volume. Jika volume tidak memiliki huruf kandar, nilai ini ADALAH NULL.
Terlindungi Boolean [baca, tulis] Jika CurrentSessionbenar, menunjukkan apakah volume saat ini dilindungi oleh UWF.
Jika CurrentSessionsalah, menunjukkan apakah volume dilindungi di sesi berikutnya setelah perangkat dimulai ulang.
VolumeName string [kunci, baca] Pengidentifikasi unik volume pada sistem saat ini. VolumeName sama dengan properti DeviceID dari kelas Win32_Volume untuk volume.

Keterangan

Anda harus menggunakan akun administrator untuk mengubah properti apa pun atau memanggil metode apa pun yang mengubah pengaturan konfigurasi.

Mengaktifkan atau menonaktifkan perlindungan UWF

Contoh berikut menunjukkan cara melindungi atau membuka proteksi volume dengan UWF dengan menggunakan penyedia Windows Management Instrumentation (WMI) dalam skrip PowerShell.

PowerShellscript membuat fungsi, Set-ProtectVolume, yang mengaktifkan atau menonaktifkan perlindungan UWF untuk volume. Skrip kemudian menunjukkan cara menggunakan fungsi .

$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

Mengelola pengecualian file dan folder UWF

Contoh berikut menunjukkan cara mengelola pengecualian file dan folder UWF dengan menggunakan penyedia WMI dalam skrip PowerShell. Skrip PowerShell membuat empat fungsi, lalu menunjukkan cara menggunakannya.

Fungsi pertama, Get-FileExclusions, menampilkan daftar pengecualian file UWF yang ada pada volume. Pengecualian untuk sesi saat ini dan sesi berikutnya yang mengikuti mulai ulang ditampilkan.

Fungsi kedua, Add-FileExclusion, menambahkan file atau folder ke daftar pengecualian UWF untuk volume tertentu. Pengecualian ditambahkan untuk sesi berikutnya yang mengikuti mulai ulang.

Fungsi ketiga, Remove-FileExclusion, menghapus file atau folder dari daftar pengecualian UWF untuk volume tertentu. Pengecualian dihapus untuk sesi berikutnya yang mengikuti mulai ulang.

Fungsi keempat, Clear-FileExclusions, menghapus semua pengecualian file dan folder UWF dari volume tertentu. Pengecualian dihapus untuk sesi berikutnya yang mengikuti mulai ulang.

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

Persyaratan

Edisi Windows Didukung
Windows Home Tidak
Windows Pro Tidak
Windows Enterprise Ya
Windows Education Ya
Windows IoT Enterprise Ya