public static int Run(string args, Action <string> writeOutput, Action <string> writeError) { var thisDir = Path.GetDirectoryName(Path.GetFullPath(typeof(SeqForwarderExeUtility).Assembly.Location)) ?? "."; var seqExe = Path.Combine(thisDir, "seq-forwarder.exe"); if (!File.Exists(seqExe)) { seqExe = Path.Combine(thisDir, @"..\..\..\Seq.Forwarder\bin\Debug\seq-forwarder.exe"); } return(CaptiveProcess.Run(seqExe, args, writeOutput, writeError)); }
static void Reconfigure(ServiceController controller, TextWriter cout) { string path; if (!ServiceConfiguration.GetServiceBinaryPath(controller, cout, out path)) { return; } var current = "\"" + typeof(Program).Assembly.Location + "\""; if (path.StartsWith(current)) { return; } var seqRun = path.IndexOf("seq-forwarder.exe\" run", StringComparison.OrdinalIgnoreCase); if (seqRun == -1) { cout.WriteLine("Current binary path is an unrecognized format."); return; } cout.WriteLine("Existing service binary path is: {0}", path); var trimmed = path.Substring(seqRun + "seq-forwarder.exe ".Length); var newPath = current + trimmed; cout.WriteLine("Updating service binary path configuration to: {0}", newPath); var escaped = newPath.Replace("\"", "\\\""); var sc = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "sc.exe"); if (0 != CaptiveProcess.Run(sc, "config \"" + controller.ServiceName + "\" binPath= \"" + escaped + "\"", cout.WriteLine, cout.WriteLine)) { cout.WriteLine("Could not reconfigure service path; ignoring."); return; } cout.WriteLine("Service binary path reconfigured successfully."); }