SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy 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 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
    PHP Code:
    com_load_typelib("Microsoft WMI Scripting V1.1 Library");
    $wmi = new COM("WinMgmts:{impersonationLevel=impersonate}"); 
    Last edited by beetle; Jan 20, 2003 at 14:13.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What info do you want to access?

    Short example - display server's ip(s):
    Code:
    <?
    $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);
    }
    ?>

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most of what is in the link I provided. System hardware, maybe software (some).
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found this article: Using Windows Management Instrumentation (WMI) in an ASP Page

    ...and translated into php:
    Code:
    <?
    // 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?)

  5. #5
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks jofa! This gives me enough of an operating reference to get up and running on my own.

    Much appreciated
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  6. #6
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Charlotte
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php5

    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.


    Quote Originally Posted by jofa
    I found this article: Using Windows Management Instrumentation (WMI) in an ASP Page

    ...and translated into php:
    Code:
    <?
    // 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?)

  7. #7
    SitePoint Member
    Join Date
    May 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  8. #8
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why dont you just switch to .net, seems obvious they give you the most power on these subjects ...
    Business as usual is off the menu folks, ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •