Zend - The PHP Company




Miscellaneous

Add Code


Process list under windows  

Type: code fragment
Added by: nikolas_
Entered: 24/08/2005
Last modified: 02/12/2005
Rating: - (fewer than 3 votes)
Views: 3293
A function that returns the running processes list of windows in an assosiative array


<?php
function tasklist()
 {
    
ob_start();
    
passthru("tasklist");
    
$ret ob_get_clean();
    
    
$ret explode"n"$ret);
    
//Key lenghts:
    
$lengths explode(" "$ret[2]);
    for ( 
$i=0$i count($lengths); $i++)
    {
        
$lengths[$i] = strlen($lengths[$i]) + 1;
    }
    
    
$tasks = array();
    for ( 
$i=3$i count($ret); $i++)
    {
        
$tasks[] = array(
            
"Name" => trim substr $ret[$i], 0$lengths[0]) ),
            
"PID" => trim substr$ret[$i], $lengths[0], $lengths[1]) ),
            
"SessionName" => trim substr$ret[$i], $lengths[1] + $lengths[0], $lengths[2]) ),
            
"Session" => trim substr$ret[$i], $lengths[2] + $lengths[1] + $lengths[0], $lengths[3]) ),
            
"Memory" => trim substr$ret[$i], $lengths[3] + $lengths[2] + $lengths[1] + $lengths[0], $lengths[4]) )
        );
    }
    return 
$tasks;
 }
?>


Usage Example


$tasks = tasklist();
var_dump ( $tasks );


Rate This Script





Search



This Category All Categories