Skip to content

Instantly share code, notes, and snippets.

@vysecurity
Forked from Arno0x/service.cs
Created September 11, 2017 14:19
Show Gist options
  • Save vysecurity/3a5858fc2d5946befbc237c9cf81404a to your computer and use it in GitHub Desktop.
Save vysecurity/3a5858fc2d5946befbc237c9cf81404a 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