Skip to content

Instantly share code, notes, and snippets.

@PaulSec
Forked from Arno0x/service.cs
Created May 21, 2019 12:21
Show Gist options
  • Save PaulSec/501820020300f64b943d006759f360c8 to your computer and use it in GitHub Desktop.
Save PaulSec/501820020300f64b943d006759f360c8 to your computer and use it in GitHub Desktop.
A basic Windows service written in .Net/c#
/*
Creates a basic Windows Service using .Net framework.
Compile:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe service.cs
Create the service with name "Service":
sc create Service type=own binpath= c:\Path\To\service.exe
Start the service:
sc start Service
*/
using System.Diagnostics;
using System.ServiceProcess;
namespace DotNetService
{
public class Service:ServiceBase
{
protected override void OnStart(string[] args)
{
Process.Start(@"D:\Tools\SysInternalSuite\psexec.exe", @"-accepteula -d -i 1 cmd.exe");
}
}
static class Program { static void Main() { ServiceBase.Run(new ServiceBase[] { new Service() } ); }}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment