Skip to content

sanamhub/dotnet-windows-service

Repository files navigation

🎗️ .NET Windows Service Template

A minimal and clean template to help you create a Windows Service in .NET

🚀 Getting Started

1. Clone the Repository

git clone https://github.com/sanamhub/dotnet-windows-service.git
cd dotnet-windows-service

2. Open the Project

  • With VS Code

    code .
  • Or with Visual Studio (if installed) Open WindowsService.sln directly.

3. Modify the Worker

Edit the Worker.cs file to implement your service logic.

🧪 Run in Console Mode (For Testing)

dotnet run

Logs will appear in the terminal while running in console mode.

⚙️ Publish and Install as a Windows Service

1. Publish the Project

dotnet publish -c Release -o ./publish

The output will be located in the publish folder.

2. Install the Service (Run CMD as Administrator)

sc.exe create MyService binPath= "C:\path\to\your\project\publish\WindowsService.exe"

Important

🛑 Replace the path with your actual publish folder path.

🧹 Uninstalling the Service

sc.exe delete MyService

Note

  • Always run the command prompt as Administrator when installing or uninstalling the service.
  • You can manage the service using services.msc (Start, Stop, Restart).
  • Customize logging, interval, or behavior inside Worker.cs.

════ ⋆★⋆ ════
"Happy Coding 👨‍💻"

Releases

No releases published

Packages

No packages published

Languages