mirror of
https://github.com/hufrea/byedpi.git
synced 2025-01-03 04:49:47 +00:00
Windows service, fix relative paths
This commit is contained in:
parent
fd0f55b72d
commit
87fec9886a
13
dist/windows/service_restart.bat
vendored
Normal file
13
dist/windows/service_restart.bat
vendored
Normal file
@ -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
|
@ -1,6 +1,5 @@
|
|||||||
#include "win_service.h"
|
#include "win_service.h"
|
||||||
#include <minwindef.h>
|
#include <windows.h>
|
||||||
#include <winsvc.h>
|
|
||||||
|
|
||||||
#define SERVICE_NAME "ByeDPI"
|
#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)))
|
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.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
|
||||||
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
|
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
|
||||||
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
||||||
|
Loading…
Reference in New Issue
Block a user