Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Connecting to WMI with PHP
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Connecting to WMI with PHP
By: James Murray
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 23
    2004-07-06

    Table of Contents:
  • Connecting to WMI with PHP
  • The Newest SQL Slang
  • The Safe Command Line “format” Command
  • Spit it Out
  • Just a Few More Words

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Connecting to WMI with PHP - The Newest SQL Slang


    (Page 2 of 5 )

    SQL has been around for a long time, but now there’s a newer query language called WQL. WQL stands for WMI Query Language, and I bet you can guess what it’s used for. WQL isn’t hard to learn at all. The hard part is getting used to how much it seems like SQL while it’s not SQL at all. WQL is actually a subset of SQL with minor changes so that it will work with WMI. A table containing all the keywords that work with WQL can be found here:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/sql_for_wmi.asp
    After you get comfortable with WQL, we’ll start talking about how to find out what information is available from the WMI.

    The easiest way I’ve actually found to list the available information provided by WMI is to open a command prompt and type in “wmic”. This will launch the command line interface to WMI. After the wmic has started type in a simple /? and it will list out all the available aliases that you can use. If you then type in the name of one of the aliases at the wmic command prompt, it will then show you all the information that can be gathered from that particular alias.  For example if you type in “CPU” at the prompt it will show you a table that contains all the data about the CPU, such as the address width, the architecture, the caption name and so on. This information isn’t very important to most people, so what we’ll want to do is use a little bit of WQL to get some useful information. If you go back to the command prompt and type in “CPU get LoadPercentage” ,it will show a little table with only the current load percentage in it.

    The most useful aliases I’ve found in WMI are OS, CPU, and LOGICALDISK. Here are some examples of WQL for these.

    This one will get the amount of free RAM, total RAM, free virtual memory, and total virtual memory, and return the value’s in bytes.

    os get FreePhysicalMemory,TotalVirtualMemorySize,
    FreeVirtualMemory,TotalVisibleMemorySize

    This returns the current CPU load in a percentage.

    cpu get loadpercentage

    This one will return the total size the name, and the free space in byte for each hard drive partition on your system.

    logicaldisk where drivetype=3 get size,name,freespace

    Now that we’ve talked about how to get some information, let’s talk about how to get our data formatted for use with PHP.

    More Windows Scripting Articles
    More By James Murray


       · $xml[] = simplexml_load_string($results) - where's the semicolon...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek