StackExchange / wmi

WMI for Go
http://godoc.org/github.com/StackExchange/wmi
MIT License
434 stars 173 forks source link

Any way you can put ups docs? #1

Closed kevinpostal closed 10 years ago

kevinpostal commented 10 years ago

I would love to use your code. Any way you can explain how to?

maddyblue commented 10 years ago

We do not recommend bundling the wmi package in with another due to a memory corruption issue during GC that we cannot track down. Instead, use the wmi/wmi application, which takes a query as arguments and prints json to stdout:

> go get github.com/StackExchange/wmi/wmi
> wmi select Name, ProcessId from Win32_Process

You'll have to look at the WMI docs to find the objects and columns you want. If you want to run many queries without spinning up a new process for each one, refer here for an implementation. There's also a few docs on godoc.

kevinpostal commented 10 years ago

Any way you can make this a useable library rather than a straight Executable?

maddyblue commented 10 years ago

Update: this comment no longer applies as the bug has been fixed.

I'm going to repeat what I said in the previous comment but rephrased and with a bit more detail.

DO NOT use the wmi package except in its own executable that either runs one query and exits or intelligently exits after N runs (like the implementation I linked). The wmi package has an incredibly horrible memory issue when the GC is turned on and WILL CORRUPT YOUR PROGRAM AND DATA. Just don't do it. We have tried to fix it but are not experts in Windows, COM, and garbage collectors. See https://github.com/mattn/go-ole/issues/13 for the progress on this issue.

If you are unconvinced and you still want to run wmi from within your application AND CAUSE IT TO PANIC AND CORRUPT YOUR MEMORY, then look at the godoc docs for documentation and the test file for an example of how to query all running processes.

ahall commented 10 years ago

Isn't it safe to use it now after your fix in go-ole yesterday?

maddyblue commented 10 years ago

The memory corruption bug has been fixed, and this now appears safe to use. But we've only been running this new version for 1 day, so it has not seen a lot of testing. It is possible, since these objects are reference counted, that we're missing something and there's a memory leak we didn't see before. We're not aware of any such bugs, though. We still advise minor caution until it's seen more use.

maddyblue commented 10 years ago

I've added some example use documentation beyond the API docs. Comment if you need more.

ahall commented 10 years ago

Perfect thanks