PHP, COM, and WMI. Help!

Hey all

Well, I’m doing my best to grasp all this, but inevitably, some important stuff is slipping through. I’m trying to access information provided by these using [URL=]this, but can’t seem to get the syntax/process correct. Anyone with COM experience in PHP know what’s up? I’ve been able to instantiate a WMI object in PHP using this

com_load_typelib("Microsoft WMI Scripting V1.1 Library");
$wmi = new COM("WinMgmts:{impersonationLevel=impersonate}");

What info do you want to access?

Short example - display server’s ip(s):

$wmi = new COM("WinMgmts:{impersonationLevel=impersonate}");
$ipconf = $wmi->ExecQuery("SELECT IPAddress
	FROM Win32_NetworkAdapterConfiguration
	WHERE IPEnabled = True");
for($i = 0; $i < $ipconf->Count; $i++)
	$ip = $ipconf->Next();

Most of what is in the link I provided. System hardware, maybe software (some).

I found this article: Using Windows Management Instrumentation (WMI) in an ASP Page

…and translated into php:

// php translation of asp script by Bill Wooten from
function showServices($vComputerName, $vClass)
	$objLocator = new COM("WbemScripting.SWbemLocator");
	if($vComputerName == "")
		$objService = $objLocator->ConnectServer();
		$objService = $objLocator->ConnectServer($vComputerName);
	$objWEBM = $objService->Get($vClass);
	$objProp = $objWEBM->Properties_;
	echo "<table border=1><tr>";
	$arrProp = $objProp->Next($objProp->Count);
	foreach($arrProp as $propItem)
		echo "<th>" .$propItem->Name ."</th>";
	echo "</tr>";
	$objWEBMCol = $objWEBM->Instances_();
	$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
	foreach($arrWEBMCol as $objItem)
		echo "<tr>";
		foreach($arrProp as $propItem)
			echo "<td>";
			eval("echo \\$objItem->" .$propItem->Name .";");
			echo "</td>";
		echo "</tr>";
	echo "</table>";
// Test the function:
showServices("", "Win32_Processor");
showServices("", "Win32_LogicalDisk");

(Working with the Collection object in php is still a mystery to me - maybe some php expert that could improve my code?)

Thanks jofa! This gives me enough of an operating reference to get up and running on my own.

Much appreciated :smiley:

This works great in PHP4 do you know how to write this to work in PHP5? I am trying to do the same in PHP5 and I am having a problem. If you could give me some direction or a script that does the same writtin in PHP5 I would be forever grateful.


Plz digest with the following question,
I have a project to do with is,

For the terminals connected to the server I have to monitor

     1. The files(Creation,deletion,changes).

     2. Softwares installed and uninstalled in the server.

     3. hardware specification with respect to the terminal.

Can I use the WMI to do this activity.

If Wat r software & hardware requirement.

can I use wmi in C#.NET/VB.NET with VS.NET 2003

If yes how to make use of it.

Can I get the tutorials for using it in C#.NET/VB.NET

Plz do reply to each question

Waiting for your anticiipation,

N. Siva shanmugam.

N. siva shanmugam.

why dont you just switch to .net, seems obvious they give you the most power on these subjects …