-
-
Save ahhh/b9c63727736ee573b282a1a9b49f7433 to your computer and use it in GitHub Desktop.
A basic Windows service written in .Net/c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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