编程运行CMD.EXE作为管理员联系在Vista中,C# [英] programatically run cmd.exe as adminstrator in vista, c#

查看:143
本文介绍了编程运行CMD.EXE作为管理员联系在Vista中,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio安装和部署项目。我在它添加.cmd脚本中。该脚本将需要管理员的privilages运行。当用户点击的setup.exe,UAC提示的管理权限用户。因此,我认为建立和SETUP.EXE中调用的所有进程将在管理运行的能力。 。所以,我提出的建立呼叫,其中包含下面的代码我的控制台应用程序

I have a visual studio setup and deployment project. I've added a .cmd script in it. The script would need administrator privilages 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.

我想通过C#程序类运行Windows Vista的administrator.I'm运行cmd.exe的。

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!

推荐答案

尝试执行运行方式命令

...

using System.Diagnostics;

...

string UserName = "user name goes here";
ProcessStartInfo p1 = new ProcessStartInfo();
  p1.FileName = "runas";
  p1.Arguments = String.Format("/env /u:{0} cmd", UserName);
Process.Start(p1);

...



(我不认为你需要一个明确的UseShellExecute)

(And I don't think you need an explicit UseShellExecute)

这篇关于编程运行CMD.EXE作为管理员联系在Vista中,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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