Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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# BitLocker值_C#_Wmi_Bitlocker - Fatal编程技术网

C# BitLocker值

C# BitLocker值,c#,wmi,bitlocker,C#,Wmi,Bitlocker,我正在尝试从远程主机获取BitLocker信息。我曾经使用PowerShell Get BitLockerVolume来完成这项工作,它将提供大量有用的信息。当我尝试使用C时,我没有得到那么多的信息。从网站上看,我找不到任何可以帮助我的东西 有人知道如何获得与C中的GetBitLockerVolume相同的输出吗 顺便说一下,这就是我在C中测试的内容: CimSession session = CimSession.Create(computerHostName); IEnumerable&l

我正在尝试从远程主机获取BitLocker信息。我曾经使用PowerShell Get BitLockerVolume来完成这项工作,它将提供大量有用的信息。当我尝试使用C时,我没有得到那么多的信息。从网站上看,我找不到任何可以帮助我的东西

有人知道如何获得与C中的GetBitLockerVolume相同的输出吗

顺便说一下,这就是我在C中测试的内容:

CimSession session = CimSession.Create(computerHostName);

IEnumerable<CimInstance> GI1 = session.QueryInstances(@"root\cimv2\Security\MicrosoftVolumeEncryption", "WQL", "SELECT * FROM Win32_EncryptableVolume");

foreach(CimInstance i in GI1)
{
    Console.WriteLine("MountPoint: {0}, Protection: {1}",
        i.CimInstanceProperties["DriveLetter"].Value,
        i.CimInstanceProperties["ProtectionStatus"].Value);
}

正如Jeroen回忆的那样,您将能够在WMI实例上获取调用方法的信息。对于文档,Win32_EncryptableVolume仅公开以下属性:

class Win32_EncryptableVolume
{
  string DeviceID;
  string PersistentVolumeID;
  string DriveLetter;
  uint32 ProtectionStatus;
};
要使用WMI和方法访问轻松获取所需信息,可以使用库:

例如,您可以这样定义您的类:

public class Win32_EncryptableVolume : WMIInstance
{
  public string DeviceID {get; set;}
  public string PersistentVolumeID {get; set;}
  public string DriveLetter {get; set;}
  public int ProtectionStatus {get; set;}

  [WMIIgnore]
  public int Version {get; set;}

  public int GetVersion()
  {
     return WMIMethod.ExecuteMethod<int>(this)
  }
}
然后你可以做一些类似的事情:

WmiHelper _helper = new WmiHelper("root\\Cimv2"); //Define the correct scope

List<Win32_EncryptableVolume> volumes = _helper.Query<Win32_EncryptableVolume>().ToList();

foreach(Win32_EncryptableVolume v in volumes)
{
    v.Version = v.GetVersion();
}

正如Jeroen回忆的那样,您将能够在WMI实例上获取调用方法的信息。对于文档,Win32_EncryptableVolume仅公开以下属性:

class Win32_EncryptableVolume
{
  string DeviceID;
  string PersistentVolumeID;
  string DriveLetter;
  uint32 ProtectionStatus;
};
要使用WMI和方法访问轻松获取所需信息,可以使用库:

例如,您可以这样定义您的类:

public class Win32_EncryptableVolume : WMIInstance
{
  public string DeviceID {get; set;}
  public string PersistentVolumeID {get; set;}
  public string DriveLetter {get; set;}
  public int ProtectionStatus {get; set;}

  [WMIIgnore]
  public int Version {get; set;}

  public int GetVersion()
  {
     return WMIMethod.ExecuteMethod<int>(this)
  }
}
然后你可以做一些类似的事情:

WmiHelper _helper = new WmiHelper("root\\Cimv2"); //Define the correct scope

List<Win32_EncryptableVolume> volumes = _helper.Query<Win32_EncryptableVolume>().ToList();

foreach(Win32_EncryptableVolume v in volumes)
{
    v.Version = v.GetVersion();
}

您使用的用户帐户很重要,DriverLetter是按用户设置的。PowerShell模块通常在PowerShell或易于反编译的.NET程序集中实现。Get命令Get-BitLockerVolume.Module | Get Module | Select Path在本例中将直接指向源。查看Get-BitLockerVolumeInternal,您将看到它使用了与您使用的相同的CIM类,但是调用了更多的方法来直接获取一些数据作为属性。您可以复制这些东西,也可以简单地使用C中的PowerShell管道直接调用Get-BitLockerVolume。谢谢@JeroenMostert!我不知道我能这样追查到源头。我希望只使用C,但在这种情况下使用PowerShell似乎更简单。@Jeroenmoster当我使用运行空间并在远程主机内部运行PowerShell时,当运行Get进程时,我会返回信息,但在使用Get BitLockerVolumeth时,我什么也得不到您使用的用户帐户很重要,DriverLetter是按用户设置的。PowerShell模块通常在PowerShell或易于反编译的.NET程序集中实现。Get命令Get-BitLockerVolume.Module | Get Module | Select Path在本例中将直接指向源。查看Get-BitLockerVolumeInternal,您将看到它使用了与您使用的相同的CIM类,但是调用了更多的方法来直接获取一些数据作为属性。您可以复制这些东西,也可以简单地使用C中的PowerShell管道直接调用Get-BitLockerVolume。谢谢@JeroenMostert!我不知道我能这样追查到源头。我希望只使用C,但在这种情况下使用PowerShell似乎更简单。@Jeroenmoster当我使用运行空间并在远程主机内部运行PowerShell时,当运行Get进程时,我会返回信息,但使用Get-BitLockerVolumeI时,我不会返回任何信息。假设public int Version=>GetVersion也可以,如果我们不关心缓存值或更新任何实例?这将节省一些初始化代码。因此,要获得与get BitLockerVolume相同的输出,我必须查询几个WMI位置并将它们全部添加到一起?@JeroenMostert Yes!。。。你的会好得多implementation@I.TDelinquent如果我们不关心缓存值或更新任何实例的话,我想您必须这样做,我想public int Version=>GetVersion也可以?这将节省一些初始化代码。因此,要获得与get BitLockerVolume相同的输出,我必须查询几个WMI位置并将它们全部添加到一起?@JeroenMostert Yes!。。。你的会好得多implementation@I.TDelinquent我想你必须这么做