You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Security.Principal;
|
|
|
|
namespace ServiceInstall
|
|
{
|
|
public static class ServiceHelper
|
|
{
|
|
private static string LidarrExe => Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "Lidarr.Console.exe");
|
|
|
|
private static bool IsAnAdministrator()
|
|
{
|
|
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
|
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
|
}
|
|
|
|
public static void Run(string arg)
|
|
{
|
|
if (!File.Exists(LidarrExe))
|
|
{
|
|
Console.WriteLine("Unable to find Lidarr.Console.exe in the current directory.");
|
|
return;
|
|
}
|
|
|
|
if (!IsAnAdministrator())
|
|
{
|
|
Console.WriteLine("Access denied. Please run as administrator.");
|
|
return;
|
|
}
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
{
|
|
FileName = LidarrExe,
|
|
Arguments = arg,
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true,
|
|
CreateNoWindow = true
|
|
};
|
|
|
|
var process = new Process { StartInfo = startInfo };
|
|
process.OutputDataReceived += OnDataReceived;
|
|
process.ErrorDataReceived += OnDataReceived;
|
|
|
|
process.Start();
|
|
|
|
process.BeginErrorReadLine();
|
|
process.BeginOutputReadLine();
|
|
|
|
process.WaitForExit();
|
|
}
|
|
|
|
private static void OnDataReceived(object sender, DataReceivedEventArgs e)
|
|
{
|
|
Console.WriteLine(e.Data);
|
|
}
|
|
}
|
|
}
|