├── SG_PersistantService
├── stdafx.cpp
├── SG_PersistantService.vcxproj.user
├── SG_PersistantService.vcxproj.filters
├── SG_PersistantService.h
├── stdafx.h
├── SG_PersistantService.vcxproj
└── SG_PersistantService.cpp
├── persistant service.gif
├── SampleApp
└── SampleApp
│ ├── SampleApp.h
│ ├── small.ico
│ ├── SampleApp.cpp
│ ├── SampleApp.ico
│ ├── SampleApp.rc
│ ├── SampleApp.vcxproj.user
│ ├── targetver.h
│ ├── framework.h
│ ├── Resource.h
│ ├── SampleApp.vcxproj.filters
│ └── SampleApp.vcxproj
├── uninstall.bat
├── .gitignore
├── README.md
├── SG_PersistantService.sln
└── LICENSE
/SG_PersistantService/stdafx.cpp:
--------------------------------------------------------------------------------
1 | #include "stdafx.h"
2 |
--------------------------------------------------------------------------------
/persistant service.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/persistant service.gif
--------------------------------------------------------------------------------
/SampleApp/SampleApp/SampleApp.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/SampleApp/SampleApp/SampleApp.h
--------------------------------------------------------------------------------
/SampleApp/SampleApp/small.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/SampleApp/SampleApp/small.ico
--------------------------------------------------------------------------------
/SampleApp/SampleApp/SampleApp.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/SampleApp/SampleApp/SampleApp.cpp
--------------------------------------------------------------------------------
/SampleApp/SampleApp/SampleApp.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/SampleApp/SampleApp/SampleApp.ico
--------------------------------------------------------------------------------
/SampleApp/SampleApp/SampleApp.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/securedglobe/PersistantService/HEAD/SampleApp/SampleApp/SampleApp.rc
--------------------------------------------------------------------------------
/uninstall.bat:
--------------------------------------------------------------------------------
1 | sc stop sg_persistantservice
2 | sc delete sg_persistantservice
3 | taskkill /f /im sampleapp.exe
4 | taskkill /f /im sg_persistantservice.exe
--------------------------------------------------------------------------------
/SampleApp/SampleApp/SampleApp.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SG_PersistantService/SG_PersistantService.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SampleApp/SampleApp/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // // Including SDKDDKVer.h defines the highest available Windows platform.
4 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
5 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
6 | #include
7 |
--------------------------------------------------------------------------------
/SampleApp/SampleApp/framework.h:
--------------------------------------------------------------------------------
1 | // header.h : include file for standard system include files,
2 | // or project specific include files
3 | //
4 |
5 | #pragma once
6 |
7 | #include "targetver.h"
8 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
9 | // Windows Header Files
10 | #include
11 | // C RunTime Header Files
12 | #include
13 | #include
14 | #include
15 | #include
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 | /.vs
34 | /bin/x64/Release
35 | /SG_PersistantService/.vs/SG_RevealerService/v17
36 | /_intermediate/x64
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PersistantService
2 | 
3 |
4 | A persistent Windows Service Proof of Concept, where the Service will run after Restart or Shutdown, and invoke a given software executable.
5 |
6 | 1. The service is installed.
7 | 2. The service starts the Sample App (unless it's already running). That's the 'Watch dog' mechanism.
8 | 3. If you shut down SampleApp.exe, the service will restart it, whilst keeping it running.
9 | 4. If you reboot, the service will start, wait for the first user to log in and then start SampleApp.exe under the logged-on user's session.
10 | 5. The service is uninstalled using the uninstall
11 |
--------------------------------------------------------------------------------
/SampleApp/SampleApp/Resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by SampleApp.rc
4 |
5 | #define IDS_APP_TITLE 103
6 |
7 | #define IDR_MAINFRAME 128
8 | #define IDD_ABOUTBOX 103
9 | #define IDM_ABOUT 104
10 | #define IDM_EXIT 105
11 | #define IDI_SAMPLEAPP 107
12 | #define IDI_SMALL 108
13 | #define IDC_SAMPLEAPP 109
14 | #define IDC_MYICON 2
15 | #ifndef IDC_STATIC
16 | #define IDC_STATIC -1
17 | #endif
18 | // Next default values for new objects
19 | //
20 | #ifdef APSTUDIO_INVOKED
21 | #ifndef APSTUDIO_READONLY_SYMBOLS
22 |
23 | #define _APS_NO_MFC 130
24 | #define _APS_NEXT_RESOURCE_VALUE 129
25 | #define _APS_NEXT_COMMAND_VALUE 32771
26 | #define _APS_NEXT_CONTROL_VALUE 1000
27 | #define _APS_NEXT_SYMED_VALUE 110
28 | #endif
29 | #endif
30 |
--------------------------------------------------------------------------------
/SG_PersistantService/SG_PersistantService.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Source Files
6 |
7 |
8 | Source Files
9 |
10 |
11 |
12 |
13 | Header Files
14 |
15 |
16 | Header Files
17 |
18 |
19 |
20 |
21 | {8c48a4a7-b230-4488-aa2d-e9b176eca8d7}
22 |
23 |
24 | {db8678ad-7319-460d-9789-7c1652acff04}
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SG_PersistantService/SG_PersistantService.h:
--------------------------------------------------------------------------------
1 | /*
2 | SG_PersistantService
3 | by Michael Haephrati haephrati@gmail.com
4 | Secured Globe Persistant Windows Service
5 | ©2019-2022 Secured Globe, Inc.
6 | https://www.securedglobe.net
7 |
8 | Explained in https://www.codeproject.com/Articles/5345258/Thank-You-for-Your-Service-Creating-a-Persistent-I
9 |
10 | version 2.0 Nov 2022
11 | */
12 |
13 | #pragma once
14 |
15 | // Customizable values
16 | #define SERVICE_NAME _T("SG_PersistantService")// Service name
17 | #define SERVICE_COMMAND_INSTALL L"Install" // The command line argument for installing the service
18 |
19 | #define SERVICE_COMMAND_Launcher L"ServiceIsLauncher" // Launcher command for NT service
20 | #define MAIN_CLASS_NAME L"ServiceClass" // Window class name for service client
21 |
22 | #define MAIN_TIMER_ID 2001
23 |
24 |
25 | void WriteToLog(LPCTSTR lpText, ...);
26 |
27 | void ReportServiceStatus(DWORD, DWORD, DWORD);
28 | void WINAPI InstallService();
29 | void ImpersonateActiveUserAndRun(WCHAR* path, WCHAR* args);
30 | std::wstring GetLoggedInUser();
31 | void WINAPI ServiceMain(DWORD dwArgCount, LPTSTR lpszArgValues[]);
32 | DWORD WINAPI CtrlHandlerEx(DWORD dwControl, DWORD dwEventType, LPVOID pEventData, LPVOID pUserData);
33 | DWORD WINAPI AppMainFunction();
34 | BOOL RunHost(LPWSTR HostExePath,LPWSTR CommandLineArguments);
35 | LRESULT CALLBACK S_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
36 |
37 |
38 |
--------------------------------------------------------------------------------
/SG_PersistantService/stdafx.h:
--------------------------------------------------------------------------------
1 | /*
2 | SG_PersistantService
3 | by Michael Haephrati haephrati@gmail.com
4 | Secured Globe Persistant Windows Service
5 | ©2019-2022 Secured Globe, Inc.
6 | https://www.securedglobe.net
7 |
8 | Explained in https://www.codeproject.com/Articles/5345258/Thank-You-for-Your-Service-Creating-a-Persistent-I
9 |
10 | version 2.0 Nov 2022
11 | */
12 |
13 | #pragma once
14 |
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 |
32 | // Common Standard Headers
33 | #include
34 | #include