如何使用C#运行带有UAC权限的命令提示符? [英] How to run command prompt with UAC rights using C#?

查看:139
本文介绍了如何使用C#运行带有UAC权限的命令提示符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用UAC权限运行命令提示符,即必须与用户右键单击并以管理员身份运行相似。



另外我想执行一套命令



例如:



I am trying since long to run command prompt with UAC rights i.e it must be similar as user right click and run as administrator.

Also I want to execute set of command

for eg:

net user administrator /active:yes
net user administrator passowrd





只有当用户以管理员身份运行cmd.exe时,才会执行上述命令。

我无法以编程方式完成此操作。



我尝试使用以下命令



the above command will execute only if the user runs cmd.exe as run as administrator.
I am not getting how to do this programmatically.

I tried with below command

runas /savecred /profile /user:Administrator "net user administrator /active:yes"





但它要求输入管理员密码因为帐户不活跃而不存在。



基本上我想做的是我的程序应该通过提示UAC调用cmd.exe即以管理员身份运行然后用户应该点击是和命令





but it asks for administrator password which does not exist as the account is not active.

Basically I want to do is that my program should call cmd.exe with prompting UAC "i.e Run as administrator" and then the user should ckick yes and the command

<pre>
net user administrator /active:yes
net user administrator passowrd
</pre>





应该运行,在这种情况下它不需要管理员密码



should run in which case it does not require administrator password

推荐答案

如果通过UAC对话框请求密码,您正在正确执行此操作。你不能绕过UAC,否则 - 谁需要这样的保护?只能通过UAC对话框授予权限提升。



您在应用程序中所能做的就是从一开始就通过创建和嵌入适当的方式请求UAC对话框application manifest

http:// msdn。 microsoft.com/en-us/library/bb756929.aspx [ ^ ]。



请不要告诉我们这不是我想要的。没有办法绕过UAC。



-SA
You are doing it correctly, if the password is requested via the UAC dialog. And you cannot bypass UAC, otherwise — who would need such "protection"? The privilege elevation can only be granted via the UAC dialog.

All you can do in your application is to request UAC dialog from the very beginning, by creating and embedding appropriate application manifest:
http://msdn.microsoft.com/en-us/library/bb756929.aspx[^].

Please don't tell us "this is not what I want". There is no a way to bypass UAC.

—SA


这篇关于如何使用C#运行带有UAC权限的命令提示符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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