Voglio avviare un processo figlio (effettivamente la stessa app della console) con privilegi elevati ma con finestra nascosta.Elevare i privilegi non funziona con UseShellExecute = false
devo fare:
var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location)
{
UseShellExecute = true, // !
Verb = "runas",
};
var process = new Process
{
StartInfo = info
};
process.Start();
e questo funziona:
var identity = new WindowsPrincipal(WindowsIdentity.GetCurrent());
identity.IsInRole(WindowsBuiltInRole.Administrator); // returns true
Ma UseShellExecute = true
crea una nuova finestra e anche io non riesco a reindirizzare l'output.
Così, quando ho Operazioni successive:
var info = new ProcessStartInfo(Assembly.GetEntryAssembly().Location)
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false, // !
Verb = "runas"
};
var process = new Process
{
EnableRaisingEvents = true,
StartInfo = info
};
DataReceivedEventHandler actionWrite = (sender, e) =>
{
Console.WriteLine(e.Data);
};
process.ErrorDataReceived += actionWrite;
process.OutputDataReceived += actionWrite;
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
Questo non elevare i privilegi e codice di cui sopra restituisce false. Perché??
BTW, è possibile scrivere 'DataReceivedEventHandler actionWrite = ...' e 'process.ErrorDataReceived + = actionWrite'. – SLaks
È possibile eseguire il test utilizzando gli eventi UseShellExecute = true, Verb = "runas" e ErrorDataReceived come commento @SLaks? – Kiquenet