Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWF_卷没有CurrentSession=False的条目_C#_Windows 10_Windows 10 Iot Enterprise_Uwf_Uwfmgr - Fatal编程技术网

C# UWF_卷没有CurrentSession=False的条目

C# UWF_卷没有CurrentSession=False的条目,c#,windows-10,windows-10-iot-enterprise,uwf,uwfmgr,C#,Windows 10,Windows 10 Iot Enterprise,Uwf,Uwfmgr,从一段时间以来,我一直试图弄清楚如何正确设置这个新的UWF(统一写入过滤器)。不幸的是,似乎只有Win 8.1 industry()的文档,而不是Win 10的文档。我希望此后没有相关的变化 我也在WindowsDevCenter上问过这个问题,但到目前为止没有得到任何回应 这是我的问题: 使用WMI提供程序,我现在启用了UWF(UWF\u Filter.Enable()),但我无法保护任何卷 此外,卷列表看起来非常奇怪:有4个入口,每个人都使用CurrentSession=True 第一种是

从一段时间以来,我一直试图弄清楚如何正确设置这个新的UWF(统一写入过滤器)。不幸的是,似乎只有Win 8.1 industry()的文档,而不是Win 10的文档。我希望此后没有相关的变化

我也在WindowsDevCenter上问过这个问题,但到目前为止没有得到任何回应

这是我的问题:

使用WMI提供程序,我现在启用了UWF(
UWF\u Filter.Enable()
),但我无法保护任何卷

此外,卷列表看起来非常奇怪:有4个入口,每个人都使用
CurrentSession=True

  • 第一种是针对没有驱动器号、只有卷id的卷
  • 第二个是C:
  • 然后有两个相同的D:
每个卷通常应该有两个入口,一个是true,一个是false,这意味着重启后应用了设置

如果我尝试对带有
DriveLetter=C:
的ManagementObject执行
Protect
,我会得到一个
访问被拒绝
异常,我假设它是当前会话的对象

另外,如果我在控制台上尝试
uwfmgr.exe Volume Protect C:
,它只会挂起:没有反应,没有错误,只有一个永远闪烁的光标编辑:原来这是另一个安装的软件引起的问题。另见下文

在保护卷之前,是否必须启用、禁用或执行其他操作

提前感谢,

塞巴斯蒂安

我的系统:

  • Windows 10物联网企业2016 LTSB x64
  • 1个带引导的250GB SSD,C:和D:
编辑:

我问了一个后续问题,包括一些其他细节和解决方法。例如,如果我使用
uwfmgr.exe volume protect c:
,它会工作,并且UWF\u volume现在突然为
c:
提供了(正确的)两个条目,一个用于当前会话,另一个用于下一个会话

但是我想避免这种情况,因为IMHO应该只能通过WMI来解决

编辑2:@sommen

分区布局如下:一个磁盘有4个分区

  • 后备箱,500MB
  • C:/,45GB
  • 未知,500MB(我想是启动备份)
  • D:/,~200GB
  • PS:


    请任何人创建标签
    uwf
    uwfmgr
    ?很好:-)

    我遇到了类似的问题,因为我无法用CurrentSession=False查询UWF_卷。但是,我做了一件事,似乎“生成”了CurrentSession=False的UWF_卷管理对象。我运行了“uwfmgr卷保护c:”。不幸的是,在您的情况下,运行此命令会导致它挂起

    你能试着在admin的cmd中运行uwfmgr吗?此外,如果您运行“uwfmgr get config”,您是否能够获取写入筛选器的当前设置

    描述中的另一件事:您说过D:有两个相同的卷,但是如果仔细查看属性,一个是CurrentSession=True,另一个是CurrentSession=False。根据文档,如果要进行更改,必须选择CurrentSession=False的管理对象(UWF_卷)


    (向下滚动到powershell脚本代码示例部分)

    首先,卷可能有多个分区。它们将显示为具有相同的驱动器标签

    e、 g

    现在这对于%systemDrive%很常见,因为它有启动分区。 您可以使用这些命令

    mountvol
    

    为您的需要找出正确的guid(或者您可以同时保护引导分区和系统分区)。还可以使用wmi查看命名空间cimv2下的Win32_卷,以获得更多信息

    一旦运行protect命令,命令行util UWFmgr似乎会创建一个UWF_卷wmi实例。文档还提示您需要自己创建一个对象

    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;
            }
        }
    
        =======> (!) im talking about this comment
    # 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."
        }
    }
    

    但是,这些文件没有提供这样做的方法。现在看来,我们需要使用命令行util,直到有人有了使用WMI提供程序的示例。

    来回答我自己的问题:到目前为止,我只有一个解决方法,但没有真正的解决方案

    检查是否有
    CurrentSession=False的条目,如果没有,则直接调用命令:

    ManagementObjectSearcher ms = new ManagementObjectSearcher(_Scope, new ObjectQuery("select * from UWF_Volume where VolumeName = \"" + volId + "\" AND CurrentSession=\"False\""));
    ManagementObjectCollection c = ms.Get();
    UInt32 res = 1;
    foreach (ManagementObject mo in c)
    {
        // entry found: do it with WMI
        res = (UInt32)mo.InvokeMethod(newState ? "Protect" : "Unprotect", new object[] { });
    }
    if (c.Count == 1 && res == 0)
        // message: success
    if (c.Count == 0)
    {
        // no entry found: invoke cmd
        ProcessStartInfo info = new ProcessStartInfo("uwfmgr.exe", "volume " + (newState ? "Protect" : "Unprotect") + @" \\?\" + volId);
        Process process = new Process();
        info.Verb = "runas";  //needs admin
        process.StartInfo = info;
        process.Start();
        process.WaitForExit();
    }
    

    这有一个副作用,即在一瞬间会弹出一个命令行窗口,但它工作得很好。

    我通过WMI创建了缺少的实例

    但是,在我的测试中,在重新启动后,丢失的UWF_卷实例经常出现。但如果没有,您可以使用
    ManagementClass.CreateInstance()
    直接创建它们

    这里的问题是官方文件并不完全正确。
    UWF\u Volume.VolumeName
    属性的说明如下:

    当前系统上卷的唯一标识符。这个 VolumeName与Win32\U卷的DeviceID属性相同 本卷的类

    发件人:

    事实上,
    DeviceID
    在用作
    UWF\u Volume.VolumeName的值之前需要稍微修改一下:

    DeviceID.Substring(4).TrimEnd('\\')
    
    因此,在删除前缀
    \\?\
    并删除任何后续斜杠之后,您可以为指定设备创建带有
    CurrentSession=false
    的实例

    这也适用于Windows 10 Pro,无需任何
    uwfmgr.exe
    。但是,官方不推荐/支持

    此外,我还无法删除实例。因此,请确保只添加正确的值

    完整示例:

    var DeviceId\u From\u Win32\u Volume=@“\\?\Volume{c2eac053-27e3-4f94-b28c-c2c53d5f4fe1}\”;//示例值
    var myDriveLetter=“C:”;//示例值
    var myDeviceId=DeviceId\u From\u Win32\u Volume.Substring(4).TrimEnd('\\');
    var wmiNamespace=“root\\standardcimv2\\embedded”;
    var className=“UWF_卷”;
    var mgmtScope=newmanagementscope{Path={NamespacePath=wmiNamespace};
    风险管理路径=
    
    ManagementObjectSearcher ms = new ManagementObjectSearcher(_Scope, new ObjectQuery("select * from UWF_Volume where VolumeName = \"" + volId + "\" AND CurrentSession=\"False\""));
    ManagementObjectCollection c = ms.Get();
    UInt32 res = 1;
    foreach (ManagementObject mo in c)
    {
        // entry found: do it with WMI
        res = (UInt32)mo.InvokeMethod(newState ? "Protect" : "Unprotect", new object[] { });
    }
    if (c.Count == 1 && res == 0)
        // message: success
    if (c.Count == 0)
    {
        // no entry found: invoke cmd
        ProcessStartInfo info = new ProcessStartInfo("uwfmgr.exe", "volume " + (newState ? "Protect" : "Unprotect") + @" \\?\" + volId);
        Process process = new Process();
        info.Verb = "runas";  //needs admin
        process.StartInfo = info;
        process.Start();
        process.WaitForExit();
    }
    
    DeviceID.Substring(4).TrimEnd('\\')