Authenticate windows commands. Untested.

This commit is contained in:
Paul Chote
2011-01-22 21:56:18 +13:00
parent a6900c256d
commit 5353ae32a6
5 changed files with 60 additions and 5 deletions

View File

@@ -13,6 +13,9 @@ using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using OpenRA.FileFormats;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO.Pipes;
namespace OpenRA.Utility
{
@@ -61,5 +64,39 @@ namespace OpenRA.Utility
}
z.Close();
}
public static string GetPipeName()
{
return "OpenRA.Utility" + Guid.NewGuid().ToString();
}
public static void CallWithAdmin(string command)
{
string pipename = Util.GetPipeName();
var p = new Process();
p.StartInfo.FileName = "OpenRA.Utility.exe";
p.StartInfo.Arguments = command + " --pipe=" + pipename;
p.StartInfo.Verb = "runas";
try
{
p.Start();
}
catch (Win32Exception e)
{
if (e.NativeErrorCode == 1223) //ERROR_CANCELLED
return;
throw e;
}
var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.In);
pipe.Connect();
using (var reader = new StreamReader(pipe))
{
while (!p.HasExited)
Console.Write(reader.ReadLine());
}
}
}
}