GithubHelp home page GithubHelp logo

wmi's Introduction

wmi

GoDoc Go Report Card

Package wmi provides a WMI Query Language (WQL) interface for Windows Management Instrumentation (WMI) on Windows.

This package uses COM API for WMI therefore it's only usable on the Windows machines.

Package reference is available at https://godoc.org/github.com/bi-zone/wmi

Fork Features

Fork is fully compatibly with the original repo. If not - please open an issue.

New features introduced in fork:

  • Go 1.11 modules support :)
  • Improved decoder:
    • support all basic types: all integer types, float32, string, bool, uintptr and time.Time
    • support slices and pointers to all basic types
    • support decoding of structure fields (see events example)
    • support structure tags
    • support JSON-like interface for custom decoding
    • suitable for decoding properties of any go-ole IDispatch object
  • Ability to perform multiple queries in a single connection
  • SWbemServices.Get + auto dereference of REF fields
  • SWbemServices.ExecNotificationQuery support
  • More other improvements described in releases page

Example

Print names of the currently running processes

package main

import (
   "fmt"
   "log"

   "github.com/bi-zone/wmi"
)

type win32Process struct {
   PID       uint32 `wmi:"ProcessId"`
   Name      string
   UserField int `wmi:"-"`
}

func main() {
   var dst []win32Process

   q := wmi.CreateQueryFrom(&dst, "Win32_Process", "")
   fmt.Println(q)

   if err := wmi.Query(q, &dst); err != nil {
   	log.Fatal(err)
   }
   for _, v := range dst {
   	fmt.Printf("%6d\t%s\n", v.PID, v.Name)
   }
}

A more sophisticated examples are located at in examples folder.

Benchmarks

Using DefaultClient, SWbemServices or SWbemServicesConnection differ in a number of setup calls doing to perform each query (from the most to the least).

Estimated overhead is shown below:

BenchmarkQuery_DefaultClient   5000  33529798 ns/op
BenchmarkQuery_SWbemServices   5000  32031199 ns/op
BenchmarkQuery_SWbemConnection 5000  30099403 ns/op

You could reproduce the results on your machine running:

go test -run=NONE -bench=Query -benchtime=120s

Versioning

Project uses semantic versioning for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch.

This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.