简体   繁体   English

使用C#读取虚拟机的驱动器信息

[英]Read drive information of virtual machine with c#

I'm still working on a small programm where I'm trying to monitor various computer data like temperature, clock speeds... (CPU, GPU, Drives, RAM). 我仍在编写一个小型程序,试图监视各种计算机数据,例如温度,时钟速度...(CPU,GPU,驱动器,RAM)。 The data is mainly received over the WMI interface of OpenHardwareMonitor, this works fine. 数据主要通过OpenHardwareMonitor的WMI接口接收,可以正常工作。 But OHM doesn't provide any useful Drive data, so I'm currently reading it from the windows WMI interface. 但是OHM没有提供任何有用的云端硬盘数据,因此我目前正在从Windows WMI界面中读取数据。 (Win32_DiskDrive) (Win32_DiskDrive)

Everything workes fine if you work on a physical machine. 如果您在物理机上工作,一切都会正常运行。 But when I try it in an Virtual Machine, I don't receive any drive data at all. 但是,当我在虚拟机中尝试它时,我根本没有收到任何驱动器数据。

Have you any idea what I should do in order to get important drive data on a virtual machine? 您是否知道我应该怎么做才能在虚拟机上获取重要的驱动器数据? I need the space used and the total drive space of the virtual drive. 我需要使用的空间和虚拟驱动器的总驱动器空间。 Furthermore it would be nice if I'm able to get the temperature and the SMART Status of the physical drives of the computer. 此外,如果我能够获得计算机物理驱动器的温度和SMART状态,那将很好。

Thanks for your help! 谢谢你的帮助!

Have you tried using System.IO functionalities? 您是否尝试过使用System.IO功能?

Take a look here , might be what you need! 在这里看看,可能是您所需要的!

This allow you doing things like (from link): 这使您可以执行以下操作(来自链接):

    // You can also use System.Environment.GetLogicalDrives to
    // obtain names of all logical drives on the computer.
    System.IO.DriveInfo di = new System.IO.DriveInfo(@"C:\");
    Console.WriteLine(di.TotalFreeSpace);
    Console.WriteLine(di.VolumeLabel);

    // Get the root directory and print out some information about it.
    System.IO.DirectoryInfo dirInfo = di.RootDirectory;
    Console.WriteLine(dirInfo.Attributes.ToString());

Also, code showing what you actually use/what isn't working would have been nice to have in your question. 另外,显示您实际使用的/不起作用的代码也很高兴出现在您的问题中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM