Skip to content
This repository was archived by the owner on Jan 22, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions wmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,10 @@ func oleInt64(item *ole.IDispatch, prop string) (int64, error) {
// CreateQuery returns a WQL query string that queries all columns of src. where
// is an optional string that is appended to the query, to be used with WHERE
// clauses. In such a case, the "WHERE" string should appear at the beginning.
func CreateQuery(src interface{}, where string) string {
// The wmi class is obtained by the name of the type. You can pass a optional
// class throught the variadic class parameter which is useful for anonymous
// structs.
func CreateQuery(src interface{}, where string, class ...string) string {
var b bytes.Buffer
b.WriteString("SELECT ")
s := reflect.Indirect(reflect.ValueOf(src))
Expand All @@ -454,7 +457,11 @@ func CreateQuery(src interface{}, where string) string {
}
b.WriteString(strings.Join(fields, ", "))
b.WriteString(" FROM ")
b.WriteString(t.Name())
if len(class) > 0{
b.WriteString(class[0])
} else {
b.WriteString(t.Name())
}
b.WriteString(" " + where)
return b.String()
}