Skip to content

Instantly share code, notes, and snippets.

@theopolis
Created October 1, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theopolis/580bcc94084831f331a0b83c5fef40ca to your computer and use it in GitHub Desktop.
Save theopolis/580bcc94084831f331a0b83c5fef40ca to your computer and use it in GitHub Desktop.
diff --git a/osquery/core/windows/wmi.cpp b/osquery/core/windows/wmi.cpp
index 43e8d1f..d336118 100644
--- a/osquery/core/windows/wmi.cpp
+++ b/osquery/core/windows/wmi.cpp
@@ -197,8 +197,6 @@ WmiRequest::WmiRequest(const std::string& query, BSTR nspace) {
std::wstring wql = stringToWstring(query);
HRESULT hr = E_FAIL;
-
- hr = ::CoInitializeEx(0, COINIT_MULTITHREADED);
hr = ::CoInitializeSecurity(nullptr,
-1,
nullptr,
diff --git a/osquery/main/shell.cpp b/osquery/main/shell.cpp
index 8f5f0bf..0274d85 100644
--- a/osquery/main/shell.cpp
+++ b/osquery/main/shell.cpp
@@ -149,6 +149,10 @@ char **table_completion_function(const char *text, int start, int end) {
#endif
int main(int argc, char *argv[]) {
+#ifdef WIN32
+ ::CoInitializeEx(0, COINIT_MULTITHREADED);
+#endif
+
// Parse/apply flags, start registry, load logger/config plugins.
osquery::Initializer runner(argc, argv, osquery::ToolType::SHELL);
@@ -188,5 +192,9 @@ int main(int argc, char *argv[]) {
retcode = profile(argc, argv);
}
+#ifdef WIN32
+ ::CoUninitialize();
+#endif
+
return retcode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment