mirror of
https://github.com/hufrea/byedpi.git
synced 2024-12-22 06:15:14 +00:00
Merge pull request #8 from lufog/windows_service_qol
Windows service, fix relative paths
This commit is contained in:
commit
bccbb475e1
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 <minwindef.h>
|
||||
#include <winsvc.h>
|
||||
#include <windows.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
Reference in New Issue
Block a user