note 52681 added to ref.com
| From: | mpg123 at thinstall dot com | Date: | Mon, 09 May 2005 20:21:36 +0000 |
| Subject: | note 52681 added to ref.com | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-89174@lists.php.net to get a copy of this message | ||
I found the lack of good online docs about how to access a windows environment very frustrating. I
finally found something here: http://www.sitepoint.com/forums/showthread.php?t=92358
but it's a php4 way. I cleaned up the code, added introspection for methods and voila. Thanks
and credit to the original posters.
<?php
// php translation of asp script by Bill Wooten from
// http://www.4guysfromrolla.com/webtech/082802-1.shtml
function showServices($vComputerName, $vClass) {
$objLocator = new COM("WbemScripting.SWbemLocator");
if($vComputerName == "") $objService = $objLocator->ConnectServer();
else $objService = $objLocator->ConnectServer($vComputerName);
$objWEBM = $objService->Get($vClass);
$objProp = $objWEBM->Properties_;
$objMeth = $objWEBM->Methods_;
foreach($objMeth as $methItem) echo "Method: " . $methItem->Name ."\r\n";
echo "\r\n";
$objWEBMCol = $objWEBM->Instances_();
foreach($objWEBMCol as $objItem) {
echo "[" . $objItem->Name . "]\r\n";
foreach($objProp as $propItem) {
$tmp = $propItem->Name;
echo "$tmp: " . $objItem->$tmp . "\r\n";
}
echo "\r\n";
}
}
// Test the function:
showServices("", "Win32_Processor");
showServices("", "Win32_LogicalDisk");
----
Manual Page -- http://www.php.net/manual/en/ref.com.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52681
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52681&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52681&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52681&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52681&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52681&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52681&report=yes
Search -- http://master.php.net/manage/user-notes.php