From 9d05897f7a3d06f5504b3bb75dd7e822e5faebf9 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 27 Feb 2014 16:28:55 -0800 Subject: Windows service works now! --- windows/ZeroTierOne/ServiceInstaller.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'windows/ZeroTierOne/ServiceInstaller.cpp') diff --git a/windows/ZeroTierOne/ServiceInstaller.cpp b/windows/ZeroTierOne/ServiceInstaller.cpp index 5945ecdf..d302d9f6 100644 --- a/windows/ZeroTierOne/ServiceInstaller.cpp +++ b/windows/ZeroTierOne/ServiceInstaller.cpp @@ -50,16 +50,19 @@ std::string InstallService(PSTR pszServiceName, PSTR pszPassword) { std::string ret; - char szPath[MAX_PATH]; + char szPathTmp[MAX_PATH],szPath[MAX_PATH]; SC_HANDLE schSCManager = NULL; SC_HANDLE schService = NULL; - if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)) == 0) + if (GetModuleFileName(NULL, szPathTmp, ARRAYSIZE(szPath)) == 0) { ret = "GetModuleFileName failed, unable to get path to self"; goto Cleanup; } + // Quote path in case it contains spaces + _snprintf_s(szPath,sizeof(szPath),"\"%s\"",szPathTmp); + // Open the local default service control manager database schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE); -- cgit v1.2.3