如何启动一个进程在C#管理员模式 [英] How to start a Process as administrator mode in C#

查看:182
本文介绍了如何启动一个进程在C#管理员模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Visual Studio的Windows应用程序项目。我已经添加了code下载安装程序更新文件。之后,它已经完成下载需要管理员权限运行安装程序。我添加了一个清单文件。

当用户点击DownloadUpdate.exe,UAC提示输入管理员权限的用户。所以,我认为在DownloadUpdate.exe创建的,并呼吁所有的进程将在管理运行的能力。所以,我提出了建立呼叫我用下面的code下载的文件:

 进程p =新工艺();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = strFile;
p.StartInfo.UseShellExecute = FALSE;
p.StartInfo.RedirectStandardOutput = TRUE;
p.StartInfo.RedirectStandardError = TRUE;
 

解决方案

试试这个:

  // Vista或更高支票
如果(System.Environment.OSVersion.Version.Major> = 6)
{
   p.StartInfo.Verb =运行方式;
}
 

另外,去清单路线为您的应用

I have a Visual Studio Windows app project. I've added code to download an installer update file. The installer after it has finished downloading would need administrator privileges to run. I have added a manifest file.

When user clicks on the DownloadUpdate.exe, UAC prompts the user for Admin permissions. So I assumed that all processes created and called within DownloadUpdate.exe will run in admin capacity. So I made the setup call my downloaded file with the following code:

Process p = new Process();
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = strFile;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;

解决方案

Try this:

//Vista or higher check
if (System.Environment.OSVersion.Version.Major >= 6)
{
   p.StartInfo.Verb = "runas";
}

Alternatively, go the manifest route for your application.

这篇关于如何启动一个进程在C#管理员模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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