mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 20:43:44 +02:00
Merge pull request #1736 from visuve/dev
Fix service installation MAX_PATH bug on Windows
This commit is contained in:
commit
381460fd97
1 changed files with 16 additions and 10 deletions
|
@ -50,20 +50,26 @@ std::string InstallService(PSTR pszServiceName,
|
||||||
PSTR pszPassword)
|
PSTR pszPassword)
|
||||||
{
|
{
|
||||||
std::string ret;
|
std::string ret;
|
||||||
char szPathTmp[MAX_PATH],szPath[MAX_PATH];
|
std::string path(0x7FFF, '\0');
|
||||||
|
|
||||||
SC_HANDLE schSCManager = NULL;
|
SC_HANDLE schSCManager = NULL;
|
||||||
SC_HANDLE schService = NULL;
|
SC_HANDLE schService = NULL;
|
||||||
SERVICE_DESCRIPTION sd;
|
SERVICE_DESCRIPTION sd;
|
||||||
LPTSTR szDesc = TEXT("ZeroTier network virtualization service.");
|
LPTSTR szDesc = TEXT("ZeroTier network virtualization service.");
|
||||||
|
|
||||||
if (GetModuleFileName(NULL, szPathTmp, ARRAYSIZE(szPath)) == 0)
|
DWORD dwCharacters = GetModuleFileName(NULL, path.data(), path.size());
|
||||||
|
|
||||||
|
if (dwCharacters == 0)
|
||||||
{
|
{
|
||||||
ret = "GetModuleFileName failed, unable to get path to self";
|
ret = "GetModuleFileName failed, unable to get path to self";
|
||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trim excess nulls which the returned size does not include
|
||||||
|
path.resize(dwCharacters);
|
||||||
|
|
||||||
// Quote path in case it contains spaces
|
// Quote path in case it contains spaces
|
||||||
_snprintf_s(szPath,sizeof(szPath),"\"%s\"",szPathTmp);
|
path = '"' + path + '"';
|
||||||
|
|
||||||
// Open the local default service control manager database
|
// Open the local default service control manager database
|
||||||
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT |
|
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT |
|
||||||
|
@ -83,7 +89,7 @@ std::string InstallService(PSTR pszServiceName,
|
||||||
SERVICE_WIN32_OWN_PROCESS, // Service type
|
SERVICE_WIN32_OWN_PROCESS, // Service type
|
||||||
dwStartType, // Service start type
|
dwStartType, // Service start type
|
||||||
SERVICE_ERROR_NORMAL, // Error control type
|
SERVICE_ERROR_NORMAL, // Error control type
|
||||||
szPath, // Service's binary
|
path.c_str(), // Service's binary
|
||||||
NULL, // No load ordering group
|
NULL, // No load ordering group
|
||||||
NULL, // No tag identifier
|
NULL, // No tag identifier
|
||||||
pszDependencies, // Dependencies
|
pszDependencies, // Dependencies
|
||||||
|
|
Loading…
Add table
Reference in a new issue