2012-01-17 08:12:22 +01:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Security.Principal;
|
|
|
|
|
2012-02-13 07:38:57 +01:00
|
|
|
namespace ServiceInstall
|
2012-01-17 08:12:22 +01:00
|
|
|
{
|
2013-04-08 00:40:13 +02:00
|
|
|
public static class ServiceHelper
|
2012-01-17 08:12:22 +01:00
|
|
|
{
|
|
|
|
private static string NzbDroneExe
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2013-01-06 09:11:14 +01:00
|
|
|
return Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, "NzbDrone.Console.exe");
|
2012-01-17 08:12:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsAnAdministrator()
|
|
|
|
{
|
|
|
|
WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
|
|
|
|
return principal.IsInRole(WindowsBuiltInRole.Administrator);
|
|
|
|
}
|
|
|
|
|
2013-04-08 00:40:13 +02:00
|
|
|
public static void Run(string arg)
|
2012-01-17 08:12:22 +01:00
|
|
|
{
|
|
|
|
if (!File.Exists(NzbDroneExe))
|
|
|
|
{
|
|
|
|
Console.WriteLine("Unable to find NzbDrone.exe in the current directory.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsAnAdministrator())
|
|
|
|
{
|
|
|
|
Console.WriteLine("Access denied. Please run as administrator.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var startInfo = new ProcessStartInfo
|
|
|
|
{
|
|
|
|
FileName = NzbDroneExe,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|