Tuesday, June 7, 2011

WMI Code Example using Kixtart

The following is a code example using Kixtart:

Additional examples can be found at:

http://www.planetmps.com/

$crlf = Chr(13) + Chr(10)

$tempstr
$Name
$Value
$locator = CreateObject("WbemScripting.SWbemLocator")
$services = $locator.ConnectServer(".", "root\aspnet")
$services.Security_.AuthenticationLevel = 0
$services.Security_.ImpersonationLevel = 3
$ob = $services.Get("ApplicationLifetimeEvent")
$objset = $ob.Instances_

For each $obj in $objset

  for each $prop in $obj.Properties_
  
    $Name = $prop.Name
    $Value = checkme($prop)
    $tempstr = $tempstr . $Name . " = " . $Value . "\n\r"
  next
  Messagebox($tempstr, "Kixtart")
  $tempstr = ""
  exit for
next

function checkme($prop)

  if vartype($Prop.Value) = -1
    $checkme = ""
  else
    if $prop.IsArray
      $Value = Join($prop.Value, ",")
      $checkme = $Value
    else
      if $prop.CIMType = 101
        if len($Prop.Value) > 0 
          $Value = $prop.Value 
          $checkme = substr($Value, 5,2) + "/" + substr($Value, 7,2) + "/" + substr($Value, 1,4) + " " + substr($Value, 9,2) + ":" + substr($Value, 11,2) + ":" + substr($Value, 13,2) 
        else
          $checkme = ""
        endif
      else
        if $prop.CIMType = 11
          if $prop.Value = 0
            $checkme = "False"
          else
            $checkme = "True"
          endif
        else
          $Value = $prop.Value
          $checkme = $Value
        endif
      endif
    endif
  endif
endfunction

No comments:

Post a Comment