PHP WMI Library for Linux
I’ve just released a WMI/PHP library which will allow you to easily WMI query Windows machines from your Linux server via PHP. It is somewhat of an extension of the CactiWMI project as it used that code base as a reference for the query and processing of the returned data. Whilst there are a number of libraries in existence for this purpose on Windows there appeared to be none for when running PHP on Linux.
So why has this all come about. In my job I’ve been working on a small helpdesk type application written in PHP. The idea being that it presents all the information about the user, computer and helpdesk ticket that we are working on in one place. It also provides a quicker interface for searching information than the existing systems on their own. For this I needed to be able to hook into Active Directory, the MSSQL job tracking DB and of course WMI data for the remote PC. All this from the Linux based server.
So I branched off some code from the CactiWMI project and initially wrote it as a simple wmi() type function to run basic queries against remote machines. This quickly became a bit of a pain as I needed to add more arguments to allow filters and then more code to decide if a filter had been supplied or not etc so dumped it and rewrote it into a WMI object.
Now what we have is a reasonably simple library which you can include into your project, create the WMI object and throw some queries at hosts. The data returned at the moment is a little rough as its just a numerically indexed multi dimensional array but should make iteration very easy. I’ll be looking for suggestions as to what I can improve as it’s the first library like this I have had to write and I’ve probably made plenty of rookie mistakes.
I’ve attached a copy of the current stable release and an example file which should get people started until I can add some documentation. I may look at releasing the helpdesk app as well as it’s come in quite useful
SVN Repository is located here http://svn.parkingdenied.com/PHPWMILib/
PHPWMILib-0.0.2.r4.tar.gz (13.3 KiB, 1,063 hits)
example.zip (569 bytes, 1,020 hits)
6 Comments
Other Links to this Post
RSS feed for comments on this post. TrackBack URI




By Nimal, March 12, 2010 @ 9:31 pm
Nice 1… Even though i never used php before, it is useful for me
Thanks
By Andy, April 22, 2010 @ 9:54 am
Thanks! Was looking for someting like this to work with setting up some IIS websites from a linux based control panel. Should save a bunch of time.
By Rob Pomeroy, August 11, 2010 @ 6:12 pm
Fab!
Need to create a CodeIgniter library for this… I’ll have a think about that.
By Ms Linux, December 20, 2010 @ 3:56 pm
Nice post
Just want to share an experience, I’ve been having trouble iterating Win32_Product to query installed softwares on Windows machine with this tool.
When I turn on debug to 10 it always gives me dcerpc_request_recv status = NT_STATUS_IO_TIMEOUT
NTSTATUS: NT code 0xc002001b – NT code 0xc002001b
but the query works fine on Win2000 machines and some XP which connected to the same hub as the linux machine which does the query
By Jim, May 7, 2011 @ 3:40 am
unfortunately you must also install Cacti nice function though…
By Ross, May 9, 2011 @ 8:30 am
Hi mate,
Not sure why you need Cacti installed.. I am using it at present without Cacti on my dev network.