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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 22
    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


     

    WINDOWS SCRIPTING ARTICLES

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway