PHP调用COM组件,需求是要读取进程的用户名,但是GetOwner这个函数(method)的输出是在参数中的([out]类参数),PHP好像没有这种用法,请教各位高人了!多谢!<?
$objLocator = new COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer(); $kkk =array('Caption','ExecutablePath');
$lll = array('GetOwner');
$buffer = _GetWMI($wmi, "Win32_Process", $kkk, $lll);echo '<pre>';
print_R($buffer);
echo '</pre>';function _GetWMI($wmi, $strClass, $strValue = array(), $strMethod = array() ) {
$objWEBM = $wmi->Get($strClass);
if( PHP_VERSION < 5 ) {
$objProp = $objWEBM->Properties_;
$arrProp = $objProp->Next($objProp->Count);
$objMeth = $objWEBM->Methods_;
$arrMeth = $objMeth->Next($objMeth->Count);
$objWEBMCol = $objWEBM->Instances_();
$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
} else {
$arrProp = $objWEBM->Properties_;
$arrMeth = $objWEBM->Methods_;
$arrWEBMCol = $objWEBM->Instances_();
}
foreach($arrWEBMCol as $objItem) {
//reset($arrProp);
$arrInstance = array();
foreach($arrProp as $propItem) {
eval("\$value = \$objItem->" .$propItem->Name .";");
if( empty( $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
} else {
if( in_array( $propItem->Name, $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
}
}
}
foreach($arrMeth as $i=>$methItem) {
if(is_array($strMethod) and count($strMethod)>0) {
if(in_array($methItem->Name,$strMethod)) {
eval("\$value2 = \$objItem->".$methItem->Name."();");
$arrInstance[$methItem->Name] = trim($value2);
}
}
}
$arrData[] = $arrInstance;
}
return $arrData;
}
?>
$objLocator = new COM("WbemScripting.SWbemLocator");
$wmi = $objLocator->ConnectServer(); $kkk =array('Caption','ExecutablePath');
$lll = array('GetOwner');
$buffer = _GetWMI($wmi, "Win32_Process", $kkk, $lll);echo '<pre>';
print_R($buffer);
echo '</pre>';function _GetWMI($wmi, $strClass, $strValue = array(), $strMethod = array() ) {
$objWEBM = $wmi->Get($strClass);
if( PHP_VERSION < 5 ) {
$objProp = $objWEBM->Properties_;
$arrProp = $objProp->Next($objProp->Count);
$objMeth = $objWEBM->Methods_;
$arrMeth = $objMeth->Next($objMeth->Count);
$objWEBMCol = $objWEBM->Instances_();
$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
} else {
$arrProp = $objWEBM->Properties_;
$arrMeth = $objWEBM->Methods_;
$arrWEBMCol = $objWEBM->Instances_();
}
foreach($arrWEBMCol as $objItem) {
//reset($arrProp);
$arrInstance = array();
foreach($arrProp as $propItem) {
eval("\$value = \$objItem->" .$propItem->Name .";");
if( empty( $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
} else {
if( in_array( $propItem->Name, $strValue ) ) {
$arrInstance[$propItem->Name] = trim($value);
}
}
}
foreach($arrMeth as $i=>$methItem) {
if(is_array($strMethod) and count($strMethod)>0) {
if(in_array($methItem->Name,$strMethod)) {
eval("\$value2 = \$objItem->".$methItem->Name."();");
$arrInstance[$methItem->Name] = trim($value2);
}
}
}
$arrData[] = $arrInstance;
}
return $arrData;
}
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货