A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Contacts
Logo. www.xtramaina.com  
Home Search E-mail
VbScriptXtra Samples/WMI samples

ActiveCompanionSet xtras for Macromedia Director

Getting drive details with WMI

Windows Management Instrumentation (WMI) is a system level component that provides management information and control in an enterprise environment. Here is the sample that enumerates different properties of the logical drive C:

vb = xtra("VbScriptXtra")

-- Obtain WMI object for drive C:
devC = vb.GetObject2("WinMgmts:win32_LogicalDisk.DeviceId='C:'", "")

-- Getting the enumeration of available properties
props = ObjSet.Properties_.__NewEnum

-- Output available properties from a collection
repeat with i = 1 to props.count
  if props[i].value <> #Null then
    put props[i].name & ":" && props[i].value
  end if
end repeat

This sample outputs following information with my drive C:.
-- "Caption: C:"
-- "Compressed: 0"
-- "CreationClassName: Win32_LogicalDisk"
-- "Description: Local Fixed Disk"
-- "DeviceID: C:"
-- "DriveType: 3"
-- "FileSystem: FAT32"
-- "FreeSpace: 158916608"
-- "MaximumComponentLength: 255"
-- "MediaType: 12"
-- "Name: C:"
-- "Size: 4194902016"
-- "SupportsFileBasedCompression: 0"
-- "SystemCreationClassName: Win32_ComputerSystem"
-- "SystemName: EUGENE"
-- "VolumeName: SYS"
-- "VolumeSerialNumber: 77963952"

Getting process details with WMI

Here is the sample that enumerates different properties of the running Director.exe process:

vb = xtra("VbScriptXtra")

-- Obtain WMI object for executing query:
ObjSet = vb.GetObject2("WinMgmts:root\cimv2","")
ObjSet.debugMode = true

-- Create System helper object
sys = xtra("VbScriptXtra").CreateWrapper(#System)

-- Looking for Director.exe process
colItems = ObjSet.ExecQuery("Select * from Win32_Process " & \
                        "where ProcessId = " & sys.ProcessId & "" )

if colItems.Count = 0 then
  alert "Process not found"
  exit
end if

-- Getting enumerator object
colEnumerator = colItems.__NewEnum

-- The object of interest
objProcessInfo = colEnumerator[1]

-- Getting its properties collection
props = objProcessInfo.Properties_.__NewEnum

-- Output available properties from a collection
repeat with i = 1 to props.count
  if props[i].value <> #Null then
    put props[i].name & ":" && props[i].value
  end if
end repeat

This sample outputs following information with my instance of Director.exe.
-- "Caption: Director.exe"
-- "CommandLine: "C:\Program Files\Macromedia\Director MX\Director.exe" "E:\test.dir""
-- "CreationClassName: Win32_Process"
-- "CreationDate: 20050412185326.250000+240"
-- "CSCreationClassName: Win32_ComputerSystem"
-- "CSName: EUGENE"
-- "Description: Director.exe"
-- "ExecutablePath: C:\Program Files\Macromedia\Director MX\Director.exe"
-- "Handle: 2752"
-- "HandleCount: 170"
-- "KernelModeTime: 31562500"
-- "MaximumWorkingSetSize: 1413120"
-- "MinimumWorkingSetSize: 204800"
-- "Name: Director.exe"
-- "OSCreationClassName: Win32_OperatingSystem"
-- "OSName: Microsoft Windows XP Professional|C:\WINDOWS|\Device\Harddisk0\Partition1"
-- "OtherOperationCount: 10253"
-- "OtherTransferCount: 30526960"
-- "PageFaults: 11696"
-- "PageFileUsage: 24903680"
-- "ParentProcessId: 3152"
-- "PeakPageFileUsage: 24928256"
-- "PeakVirtualSize: 86757376"
-- "PeakWorkingSetSize: 25165824"
-- "Priority: 8"
-- "PrivatePageCount: 24903680"
-- "ProcessId: 2752"
-- "QuotaNonPagedPoolUsage: 7720"
-- "QuotaPagedPoolUsage: 57348"
-- "QuotaPeakNonPagedPoolUsage: 7952"
-- "QuotaPeakPagedPoolUsage: 60120"
-- "ReadOperationCount: 2790"
-- "ReadTransferCount: 3186129"
-- "SessionId: 0"
-- "ThreadCount: 5"
-- "UserModeTime: 352500000"
-- "VirtualSize: 86720512"
-- "WindowsVersion: 5.1.2600"
-- "WorkingSetSize: 25165824"
-- "WriteOperationCount: 48"
-- "WriteTransferCount: 1246"

Where to find more info about WMI?

More information about WMI is available at MSDN.

VbScriptXtra provides autodocumentation feature allowing you to see what you can do with particular object instance. Just create a recordset object and type in Messages window:
put interface(devC)
ObjectBrowser xtra - autodocumentation companion for VbScriptXtra - will show all available interfaces, methods, properties and enumerations.

ObjectBrowser xtra is a part of ActiveCompanionSet. It is available to Download.

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com