Closed gbrayut closed 3 years ago
To call a method, you need to retrieve the class and call an object like this
// Connect to namespace
// root/PanasonicPC = winmgmts:\\.\root\PanasonicPC
serviceRaw, err := oleutil.CallMethod(wmi, "ConnectServer", nil, "root/PanasonicPC")
if err != nil {
log.Panic(err)
}
service := serviceRaw.ToIDispatch()
defer serviceRaw.Clear()
// Get class
setBiosRaw, err := oleutil.CallMethod(service, "Get", "SetBIOS4Conf")
if err != nil {
log.Panic(err)
}
setBios := setBiosRaw.ToIDispatch()
defer setBiosRaw.Clear()
// Run method
resultRaw, err := oleutil.CallMethod(setBios, "AccessAuthorization", "letmein")
resultVal := resultRaw.Value().(int32)
I'm extremely interested in this. How can I help make this happen? Would you accept a PR?
@JamesCullum Were you able to get that working external to this library, or did you put that inside this package?
EDIT: Nevermind, I see now that it relies on wmi
as created in the CreateQuery
method. I've got your code working, I think. Would a PR be reviewed and accepted?
EDIT 2: Okay, yes, I've triply confirmed I have this working. Let me know if you want the PR...
Hey @mholt,
It's a separate code, that is dependant on oleutil
& wmi
- not specificially this wrapper.
My code is more of a sample to show how to do it. I think a RP would be useful, but then it would need a more clean interface. Do you want to create one or how do we want to do it?
I'm not sure how the maintenance of this repository works, it looks not properly maintained.
@JamesCullum Yeah, I think I have an idea of what I want it to look like, but I would appreciate your review so it can handle your use cases, too. (My use case so far is only a single method.)
It doesn't appear to be maintained anymore :( So I'm thinking of forking it and making the change to my own repo...
@mholt "not maintained" may be slight overstatement, but yeah, we haven't needed a lot of changes lately. Can definitely review a pr if you want.
Yay! I'll try to put one together today or tomorrow!
(I meant no offense of course. This library has already saved my bacon at least twice.)
Feel free to take a look at https://github.com/StackExchange/wmi/pull/45
Thank you for the quick work. Reviewed the changes and put that into the PR.
In addition to WMI queries it would be very helpful if I could call specific methods on WMI classes. This would allow access to a bunch of things that cannot be directly accessed via WQL. For instance, the following Powershell can be used to call a WMI method on a class to get details about DSC (Run on ny-rdp01 for example).
I would like to to be able to create a MSFT_DSCConfigurationStatus struct in go that has the properties I want, then populate that struct using something like the current wmi.Query function.
Looking at the current code this should be possible using SWbemObject and SWbemMethod
I'll see if I am able to create something that works and then create a pull request for discussion.