I am trying to rewrite a C++ program that that retrieves all installed and superseded KBs on a Windows computer in Go.
The C++ program retrieves these KBs by querying for KBs from two different sources:
SELECT * FROM Win32_QuickFixEngineering
IUpdateSearcher::GetTotalHistoryCount
and IUpdateSearcher::QueryHistory
I am seeking help with translating #1 to Go.
I thought the best library I could use for this is go-ole. As an example that uses this library, I looked at the source code for github.com/ceshihao/windowsupdate. I found that this library has the following in order to create an object for querying the update history (source):
unknown, err := oleutil.CreateObject("Microsoft.Update.Session")
I believe this is roughly equivalent to this part of the C++ program I am rewriting (this is from the part that corresponds to item 2 in the list at the beginning of this post):
result = updateSession.CoCreateInstance(CLSID_UpdateSession, nullptr, CLSCTX_INPROC_SERVER);
However, I do not know how to translate this line from a different part of the C++ program (this is from the part that corresponds to item 1 in the list at the beginning of this post):
CComPtr<IWbemLocator> pLoc;
// <...>
// Obtain the initial locator to Windows Management
// on a particular host computer.
hres = pLoc.CoCreateInstance(CLSID_WbemLocator, nullptr, CLSCTX_INPROC_SERVER);
I assume the equivalent Go will be something like this:
unknown, err := oleutil.CreateObject("<mystery string>")
I tried looking at CLSID_WbemLocator
's definition using Visual Studio's "Go To Definition" feature, but it is just declared as
EXTERN_C const CLSID CLSID_WbemLocator;
which isn't very helpful.
My question is this: How can I determine what I should use as "<mystery string>"
in order to create an object that is equivalent to what the C++ code creates with CLSID_WbemLocator
?
Here is the link to IWbemLocator interface documentation.
CLSID_WbemLocator
is declared as extern in Wbemcli.h
header file for C programs and the CLSID (GUID) constant itself is stored in the library file Wbemuuid.lib
. However, for C++ programs it is also defined in Wbemcli.h
header file.
From the Wbemcli.h
header file:
EXTERN_C const CLSID CLSID_WbemLocator;
#ifdef __cplusplus
class DECLSPEC_UUID("4590f811-1d3a-11d0-891f-00aa004b2e24")
WbemLocator;
#endif
From the Wbemuuid.lib
library (file wbemcli_i.obj
):
From the registry key HKEY_CLASSES_ROOT\CLSID\{4590F811-1D3A-11D0-891F-00AA004B2E24}
:
So the name is simply WBEM Locator
.