在 vista 中以管理员身份以编程方式运行 cmd.exe,C#
我有一个视觉工作室设置和部署项目。 我在其中添加了一个 .cmd 脚本。 该脚本需要管理员权限才能运行。 当用户单击 setup.exe 时,UAC 会提示用户授予管理员权限。 因此,我假设在 setup.exe 中创建和调用的所有进程都将以管理员身份运行。 因此,我进行了设置调用我的控制台应用程序,其中包含以下代码。
ProcessStartInfo p1 = new ProcessStartInfo();
p1.UseShellExecute = true;
p1.Verb = "runas";
p1.FileName = "cmd.exe";
Process.Start(p1);
所以它应该可以工作,因为它是在管理员空间下运行的。
我想以管理员身份通过 C# 进程类运行 cmd.exe。我正在运行 Windows Vista。
我试过 没用! 我能做些什么?
I have a visual studio setup and deployment project. I've added a .cmd script in it. The script would need administrator privileges to run. When user clicks on the setup.exe, UAC prompts the user for Admin permissions. So I assumed that all processes created and called within setup.exe will run in admin capacity. So I made the setup call my console application which contains the following code.
ProcessStartInfo p1 = new ProcessStartInfo();
p1.UseShellExecute = true;
p1.Verb = "runas";
p1.FileName = "cmd.exe";
Process.Start(p1);
So it should've worked as it's run under administrator space.
I want to run cmd.exe through c# process class as an administrator.I'm running windows vista.
I tried
didn't work! What can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试执行
runas
命令:(而且我认为您不需要显式的 UseShellExecute)
Try executing the
runas
command:(And I don't think you need an explicit UseShellExecute)
试试这个,这对我有用。
阿舒托什
Just Try this, This worked for Me.
Ashutosh