C到管理员#如何运行一个进程(带参数)升高CMD [英] C# how to run a process(with arguments) through an administrator elevated cmd
本文介绍了C到管理员#如何运行一个进程(带参数)升高CMD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " +"processNeedToRun")
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
Verb ="runas"
};
我用上面的code通过cmd,在C#中运行一个进程。
I use the above code to run a process through cmd in C#.
不过,问题是:
- 在processNeedToRun运行时需要的参数。
- 即使我设置动词=运行方式时,Windows 7仍然提示了迅速提升对话框。
是否有可能满足所有要求?
Is it possible to meet all the requirements?
推荐答案
如果是这样的启动进程 processNeedToRun
不升高,再有就是没有办法避免在提升对话框。这样做将是一个安全漏洞。所以,你只是将不得不忍受的提升提示。
If the process that's launching processNeedToRun
is not elevated, then there is no way to avoid the elevation dialog. Doing so would be a security hole. So you're just going to have to live with the elevation prompt.
添加参数 processNeedToRun
是没有问题的,但。您可以将它们只是添加到您传递给的ProcessStartInfo
参数:
Adding arguments to processNeedToRun
is no problem, though. You can just add them to the arguments you pass to ProcessStartInfo
:
var procStartInfo = new ProcessStartInfo("cmd", "/c processNeedToRun arg1 arg2");
这篇关于C到管理员#如何运行一个进程(带参数)升高CMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文