wmi in boo

# The following is a very simple example of using wmi from boo
import System
import System.Collections
import System.Data
import Boo.Lang
import System.Management
import System.Windows.Forms

class WmiApp:
    _tb as TextBox
    _dgv as DataGridView
    [STAThread]
    def Run():
        f = Form(Text: “Hello, boo!”)
        _tb = TextBox(Text: “SELECT * FROM Win32_Service”, Dock: DockStyle.Top)
        _dgv = DataGridView(Dock: DockStyle.Fill)
        b = Button(Text: “Click Me!”, Dock: DockStyle.Top)
        b.Click += ButtonClick
        f.Controls.Add(_dgv)
        f.Controls.Add(b)
        f.Controls.Add(_tb)

        Application.Run(f)
    def ButtonClick(args, sender):
        WMIQuery(_tb.Text)
    def WMIQuery(query as string):
        qry = SelectQuery(query)
        ds = DataSet()
        table = ds.Tables.Add(“WMI”)
        mos = ManagementObjectSearcher(qry)
        loaded = false
        moc as ManagementObjectCollection
        moc = mos.Get()
        for prop as PropertyData in (array(moc)[0] as ManagementObject).Properties:
            table.Columns.Add(prop.Name)
        moa = array(moc)
        mo as ManagementObject
        for i in range(0, moc.Count):
            mo = moa[i]
            row = table.NewRow()
            for prop as PropertyData in mo.Properties:
                row[prop.Name] = prop.Value
            table.Rows.Add(row)

        _dgv.DataSource = table

WmiApp().Run()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s