diff --git a/dist/windows/service_restart.bat b/dist/windows/service_restart.bat new file mode 100644 index 0000000..5e6aaaf --- /dev/null +++ b/dist/windows/service_restart.bat @@ -0,0 +1,13 @@ +@echo off +title ByeDPI - Restart Service + +echo This script should be run with administrator privileges. +echo Right click - run as administrator. +echo Press any key if you're running it as administrator. +pause + +set svc_name="ByeDPI" + +sc stop %svc_name% +sc start %svc_name% +pause \ No newline at end of file diff --git a/win_service.c b/win_service.c index b7052c5..0bfd7a4 100644 --- a/win_service.c +++ b/win_service.c @@ -1,6 +1,5 @@ #include "win_service.h" -#include -#include +#include #define SERVICE_NAME "ByeDPI" @@ -29,6 +28,15 @@ void service_ctrl_handler(DWORD request) void service_main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) { + // Current working directory for services is %WinDir%\System32, this breaks + // relative paths. Set working directory to the directory of the executable file. + char file_name[_MAX_PATH]; + GetModuleFileNameA(NULL, file_name, sizeof(file_name)); + char working_dir[_MAX_PATH], _tmp[_MAX_DIR]; + _splitpath_s(file_name, working_dir, _MAX_DRIVE, _tmp, _MAX_DIR, NULL, 0, NULL, 0); + strcat_s(working_dir, sizeof(working_dir), _tmp); + SetCurrentDirectoryA(working_dir); + ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ServiceStatus.dwCurrentState = SERVICE_RUNNING; ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;