From: Gunnar Beutner Date: Tue, 12 May 2015 13:44:44 +0000 (+0200) Subject: Determine NSClient++ installation path using MsiGetComponentPath X-Git-Tag: v2.4.0~662 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=62c755f88c2b64f1679afae4330e3480e04884b9;p=icinga2 Determine NSClient++ installation path using MsiGetComponentPath fixes #9256 --- diff --git a/itl/command-nscp-local.conf b/itl/command-nscp-local.conf index d8f092762..ed97fad50 100644 --- a/itl/command-nscp-local.conf +++ b/itl/command-nscp-local.conf @@ -18,13 +18,13 @@ ******************************************************************************/ if (!globals.contains("NscpPath")) { - NscpPath = "C:\\Program Files\\NSClient++" + NscpPath = msi_get_component_path("{5C45463A-4AE9-4325-96DB-6E239C034F93}") } object CheckCommand "nscp-local" { import "plugin-check-command" - command = [ "$nscp_path$\\nscp.exe", "client" ] + command = [ NscpPath, "client" ] arguments = { "-q" = { diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 726c490a9..900d3535b 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -63,7 +63,7 @@ if(UNIX OR CYGWIN) endif() if(WIN32) - target_link_libraries(base ws2_32 dbghelp shlwapi) + target_link_libraries(base ws2_32 dbghelp shlwapi msi) endif() set_target_properties ( diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 5e6ff0743..afdfa61bf 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -30,6 +30,9 @@ #include #include #include +#ifdef _WIN32 +#include +#endif /* _WIN32 */ using namespace icinga; @@ -51,6 +54,9 @@ REGISTER_SAFE_SCRIPTFUNCTION(string, &ScriptUtils::CastString); REGISTER_SAFE_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber); REGISTER_SAFE_SCRIPTFUNCTION(bool, &ScriptUtils::CastBool); REGISTER_SAFE_SCRIPTFUNCTION(get_time, &Utility::GetTime); +#ifdef _WIN32 +REGISTER_SAFE_SCRIPTFUNCTION(msi_get_component_path, &ScriptUtils::MsiGetComponentPathShim); +#endif /* _WIN32 */ String ScriptUtils::CastString(const Value& value) { @@ -264,3 +270,16 @@ void ScriptUtils::Assert(const Value& arg) BOOST_THROW_EXCEPTION(std::runtime_error("Assertion failed")); } +#ifdef _WIN32 +String ScriptUtils::MsiGetComponentPathShim(const String& component) +{ + TCHAR productCode[39]; + if (MsiGetProductCode(component.CStr(), productCode) != ERROR_SUCCESS) + return ""; + TCHAR path[2048]; + DWORD szPath = sizeof(path); + path[0] = '\0'; + MsiGetComponentPath(productCode, component.CStr(), path, &szPath); + return path; +} +#endif /* _WIN32 */ \ No newline at end of file diff --git a/lib/base/scriptutils.hpp b/lib/base/scriptutils.hpp index 2f6deb584..15bf1169d 100644 --- a/lib/base/scriptutils.hpp +++ b/lib/base/scriptutils.hpp @@ -50,6 +50,9 @@ public: static DynamicObject::Ptr GetObject(const Type::Ptr& type, const String& name); static Array::Ptr GetObjects(const Type::Ptr& type); static void Assert(const Value& arg); +#ifdef _WIN32 + static String MsiGetComponentPathShim(const String& component); +#endif /* _WIN32 */ private: ScriptUtils(void);