From 83fa44ce42c67837dad30ba1538bf1fa8c49a47d Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 23 Apr 2016 21:32:42 +0200 Subject: [PATCH] Fix starting tinc as a service on Windows. Don't assume tincd.exe is in the working directory, especially now that chdir() is called very early. We use GetModuleFileName() instead. --- src/process.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/process.c b/src/process.c index 5d78c295..5bb7eb3d 100644 --- a/src/process.c +++ b/src/process.c @@ -62,12 +62,9 @@ static bool install_service(void) { return false; } - if(!strchr(program_name, '\\')) { - GetCurrentDirectory(sizeof command - 1, command + 1); - strncat(command, "\\", sizeof command - strlen(command)); - } - - strncat(command, program_name, sizeof command - strlen(command)); + HMODULE module = GetModuleHandle(NULL); + GetModuleFileName(module, command + 1, sizeof command - 1); + command[sizeof command - 1] = 0; strncat(command, "\"", sizeof command - strlen(command)); -- 2.20.1