robpot891
10/9/2018 - 5:56 PM

A basic Windows service written in .Net/c#

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() } ); }}
}