Note!
This sample uses a Windows service written in C# and targeting .NET Framework 4.8.
The same overall approach can be used for testing and installing other Windows services as well, even if their implementation differs.
I am attaching a sample project that shows how to install and test a Windows service in the following scenarios:
- running under the LocalSystem account
- running under a specified user account
The sample package also includes an Advanced Installer project, together with all required resources, so it can be built and tested directly.
Service logging behavior
The sample service writes entries to a log file when the service:
- starts
- stops
Log file location
The service writes the log file under the Windows Common Application Data location.
In this sample, the log file path is:
Code: Select all
%ProgramData%\Caphyon\ServiceSample\ServiceHeartbeat.logSo, once the service is started or stopped, the log file should be created there automatically.
The output can look like this:
Code: Select all
2026-04-21 14:38:09 - Service started under Local System account
2026-04-21 14:39:30 - Service stopped under '<ComputerName>\<LogonUser>' account
- the service start/stop lifecycle
- the account used to run the service
Manual testing with SC.exe
Before configuring any service installation through the installer, make sure the service can be installed, started and stopped outside the installer.
Running these command will ensure the service installation under the LocalSystem account:
Code: Select all
sc.exe create ADemoServiceByCaphyonAsSystem binPath="<service_path>"
sc.exe start ADemoServiceByCaphyonAsSystemFor configuring the service to run under a specified account, run this command:
sc.exe create ADemoServiceByCaphyonAsUser binPath="<service_path>" obj=".\<YourUsername>" password="TheAccountPassword"
sc.exe start ADemoServiceByCaphyonAsUser
Important note for custom user accounts
If the service is installed under a custom user account, that account must have the Windows user right:
- Log on as a service
This can be verified in:
- Local Security Policy
- Security Settings > Local Policies > User Rights Assignment > Log on as a service
Notes!
LocalSystem typically does not require manual assignment of the Log on as a service right.
Installer-based service configuration
Once the service was tested and everything is working as expected, we can configure the installer to handle service installation!
1) Add resources in the Files and Folders view
2.1 Create service that runs under the LogonUser
To configure the service that runs under specified account, make sure you specify the user and passowrd under the Account section.
2.2 Create service that runs under LocalSystem account
Feel free to download the sample project attached.
All the best,
Advanced Installer Team
FOLLOW US
Get the latest news in Application Packaging