PHP5 + IIS + WMI = 1 understood headache

windows

Guest
I've got a function that I found on the net that works to read the wmi information (provided you have the correct credentials).

however I am looking to expand the functionallity of this to include the ability to say kill processes / start / stop / restart services

I think it is just the matter of changing the method, and it would probably work (but I don't understand what to change it to.

below is the function I use (PHP), and in comments below that is the vbscript for the same to items.

any help wouldbe greatly appreciated.

thx

<?php
function procinfo($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)

$objWEBMCol = $objWEBM->Instances_();

foreach($objWEBMCol as $objItem) {


foreach($objProp as $propItem) {
$tmp = $propItem->Name;
if ($tmp == "Caption") {
echo "<td style='border-top-width: thin; border-left-width: thin;
border-bottom-width: thin; border-right-width: thin'>" . $objItem->$tmp . "</td>";
}

//}
}

echo "</tr>";
}


}

$pinfo = "Win32_Process";

//called as follows
//this is formatted to work with the remainder of the script the script
//I am putting together, however
//you can see it calls the processes on the local system.


procinfo(".",$pinfo);

?>





<?

/*

This is all vbscript examples of the same thing as I want to do and what the function currently does

'this example terminates a process the user types in

On Error Resume Next

computer = InputBox("Enter the computer name","Terminate Process","localhost")

PName = InputBox("Enter the name of the process to terminate","Terminate Process")

Set Processes = getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computer & "\root\cimv2").execquery("Select * from win32_Process where Name = '" & PName & "'")

for each process in processes
process.terminate
next




' this example lists the processes running on a specified system

On Error Resume Next

computer = InputBox("Enter the computer name","List Processes","localhost")


Set Processes = getobject("winmgmts:{impersonationlevel=impersonate}!\\" & computer & "\root\cimv2").execquery("Select * from win32_Process")

for each process in processes

wscript.echo "process: " & process.description & vblf

next

*/
?>because you are using a Windows COM object, i suggest you lookup it in MSDN library
<!-- m --><a class="postlink" href="http://msdn.microsoft.com/library/">http://msdn.microsoft.com/library/</a><!-- m -->


$objLocator = new COM("WbemScripting.SWbemLocator");

this wraps a windows COM object into a PHP object, so you can use all its method as you would normally use in windows developement.I have looked on there, however my issue is with this area:


for each process in processes
process.terminate
next


in particular the line

process.terminate


I don't understand how to call that line.
using php.
 
Back
Top