beetle
January 20, 2003, 7:58pm
1
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=http://www.php.net/manual/en/ref.com.php]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}");
jofa
January 23, 2003, 4:39am
2
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();
print_r($ip->IPAddress);
}
?>
beetle
January 23, 2003, 7:30am
3
Most of what is in the link I provided. System hardware, maybe software (some).
jofa
January 27, 2003, 6:11pm
4
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
// 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_;
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>";
reset($arrProp);
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?)
beetle
January 27, 2003, 6:30pm
5
Thanks jofa! This gives me enough of an operating reference to get up and running on my own.
Much appreciated
bneese
September 20, 2004, 3:52pm
6
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.
jofa:
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
// 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_;
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>";
reset($arrProp);
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?)
Hi,
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,
Regards,
N. Siva shanmugam.
Regards,
N. siva shanmugam.
Galo
May 27, 2006, 7:15am
8
why dont you just switch to .net, seems obvious they give you the most power on these subjects …