普通网友 2015-10-07 19:57
浏览 81

使用WMI和PHP显示远程硬盘

need some help with my dashboard. I played arround with WMI for Windows to get some data from my host. I used this to connect to my host:

$pc = "192.168.xxx.xxx"; //IP of the PC to manage

$WbemLocator = new COM ("WbemScripting.SWbemLocator");
$WbemServices = $WbemLocator->ConnectServer($pc, 'root\\cimv2', 'username', 'password');
$WbemServices->Security_->ImpersonationLevel = 3;

$wmi_disks            =    $WbemServices->ExecQuery("Select * from Win32_LogicalDisk");
$wmi_computersystem   =    $WbemServices->ExecQuery("Select * from Win32_ComputerSystem");
$wmi_operatingsystem  =    $WbemServices->ExecQuery("Select * from Win32_OperatingSystem");
$wmi_networkadapter   =    $WbemServices->ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPENabled = 'True'");

i can display the ip adress and some other things.

My Problem is that i can not display the free space from my hosts hard drive. How can i get this code to work with my host:

$fso = new COM('Scripting.FileSystemObject');
$D = $fso->Drives;
$type = array("unbekannt","herausnehmbar","Festplatte","Netzwerk","CD-ROM","RAM Disk");
foreach($D as $d ){
   $dO = $fso->GetDrive($d);
   $s = "";
   if($dO->DriveType == 3){
       $n = $dO->Sharename;
   }else if($dO->IsReady){
       $n = $dO->VolumeName;
       $s = file_size($dO->FreeSpace) . " frei von: " . file_size($dO->TotalSize);
   }else{
       $n = "[Geräte mit Wechselmedien]";
   }

echo "Drive " . $dO->DriveLetter . ": - " . $type[$dO->DriveType] . " - " . $n . " - " . $s . "
";

}

  function file_size($size)
  {
  $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
  return $size ? round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $filesizename[$i] : '0 Bytes';
  }

i used PHP.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大