Simple self restartable windows service

To make a self restartable service simple cmd script may be used.
Code is in C#:

private void RestartSrv()
{
	_log.Debug($"RestartSrv()");
	try
	{
		var name = "SomeServiceName";

		var f = @"C:\restart.cmd"; // put this somewhere

		_log.Trace($"creating {f}");

		var cmd = new string[]
		{
			"@ECHO OFF",
			$"net stop {name}",
			"PING -n 20 127.0.0.1 > NUL",
			$"net start {name}",
		};

		File.WriteAllLines(f, cmd, Encoding.ASCII);

		_log.Trace($"launching {f}");
		var nfo = new ProcessStartInfo(f);
		Process.Start(nfo);
	}
	catch (Exception ex)
	{
		_log.Error(ex, "RestartSrv()");
	}
	
}

Kill windows service

To kill windows service forcefully:

C:\WINDOWS\system32>sc queryex "Bonjour Service"

SERVICE_NAME: Bonjour Service
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
        PID                : 2688
        FLAGS              :

C:\WINDOWS\system32>taskkill /F /PID 2688