Skip to content

Instantly share code, notes, and snippets.

@Arno0x
Created September 5, 2017 07:57
Show Gist options
  • Save Arno0x/90eb09adee93eb8ce763e59c014983e5 to your computer and use it in GitHub Desktop.
Save Arno0x/90eb09adee93eb8ce763e59c014983e5 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