运行提升的进程 [英] Run elevated process

查看:195
本文介绍了运行提升的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行具有以下code一个cmd命令:

I am trying to run a cmd command with the following code:

ProcessStartInfo cmd = new ProcessStartInfo("cmd.exe");
cmd.RedirectStandardInput = true;
cmd.RedirectStandardOutput = true;
cmd.RedirectStandardError = true;
cmd.UseShellExecute = false;
cmd.CreateNoWindow = true;
cmd.WindowStyle = ProcessWindowStyle.Hidden;
Process exec = Process.Start(cmd);
exec.StandardInput.WriteLine("sc create \"BaliService\" binPath= \"{0}\\BaliService.exe\"", Directory.GetCurrentDirectory());

这个命令需要管理员privelages,如果我下运行cmd以管理员身份,然后键入它完美的作品而不是当我运行这个应用程序作为管理员的命令。我已经加入

This command requires admin privelages, if I run cmd as administrator and type the command it works perfectly but not when I run this app as admin. I have added

< requestedExecutionLevel水平=requireAdministratoruiAccess =FALSE/>

到UAC提示每次我打开exe文件时的清单文件。

to a manifest file which prompts uac each time I open the exe.

我看到的这多个问题,他们都似乎表明高架的应用程序下运行都会有相同的权利的过程,但这不是为我工作。

I have seen multiple questions on this and they all seem to suggest any processes run under an elevated app will have the same rights but this isn't working for me.

我曾尝试 cmd.Verb =运行方式; ,但没有骰子。

I have tried cmd.Verb = "runas"; but no dice.

推荐答案

您需要设置 UseShellExecute 真正动词来得到尊重,必须将其设置为假来重定向标准输出。你不能两者都做。

You need to set UseShellExecute to true for the Verb to be respected and it must be set to 'false' to redirect standard output. You can't do both.

我是pretty确保Windows还不会让您能够在管理/非管理员安全边界重定向标准输入/输出/错误。你必须找到一个不同的方式来获得运行以管理员程序的输出。

I'm pretty sure Windows also won't allow you to redirect standard input/output/error across the admin/non-admin security boundary. You'll have to find a different way to get output from the program running as admin.

我没看过这篇文章,但是这可能给你更多的信息:<一href=\"http://www.$c$cproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx\">http://www.$c$cproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx

I didn't read this article, but this may give you more information: http://www.codeproject.com/KB/vista-security/UAC__The_Definitive_Guide.aspx

这篇关于运行提升的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆