提升进程权限编程? [英] Elevating process privilege programatically?

查看:235
本文介绍了提升进程权限编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装使用InstallUtil.exe一个服务,而是通过的Process.Start调用。这里的code:

I'm trying to install a service using InstallUtil.exe but invoked through Process.Start. Here's the code:

ProcessStartInfo startInfo = new ProcessStartInfo (m_strInstallUtil, strExePath);
System.Diagnostics.Process.Start (startInfo);

,其中m_strInstallUtil是完全合格的路径和EXE到InstallUtil.exe和strExePath是完全合格的路径/名我的服务。

where "m_strInstallUtil" is the fully qualified path and exe to InstallUtil.exe and "strExePath" is the fully qualified path/name to my service.

运行从提升的命令提示符下工作的命令行语法;从我的应用程序运行(使用上述code)不。我以为我处理一些工艺提升的问题,所以我将如何运行我的程序在提升状态?我需要看的ShellExecute这个?

Running the command line syntax from an elevated command prompt works; running from my app (using the above code) does not. I assume I'm dealing with some process elevation issue, so how would I run my process in an elevated state? Do I need to look at ShellExecute for this?

这是所有在Windows Vista上。我运行的过程中,在VS2008调试器提升到管理员权限。

This is all on Windows Vista. I am running the process in the VS2008 debugger elevated to admin privilege.

我也尝试设置startInfo.Verb =运行方式, - 这似乎并没有解决问题。

I also tried setting "startInfo.Verb = "runas";"--it didn't seem to solve the problem.

推荐答案

您可以显示新的程序应当与提升的权限由您的StartInfo对象的动词属性设置为运行方式启动,具体如下:

You can indicate the new process should be started with elevated permissions by setting the Verb property of your startInfo object to 'runas', as follows:

startInfo.Verb = "runas";

这将导致Windows行为,如果这个过程已经开始从资源管理器中的以管理员身份运行菜单命令。

This will cause Windows to behave as if the process has been started from Explorer with the "Run as Administrator" menu command.

这确实意味着UAC提示上来了,需要由用户进行确认:如果这是不可取的(例如,因为它会在一个漫长的过程中间发生),你需要运行整个通过主机进程以提升的权限嵌入相应的体现在您的应用程序要求在highestAvailable的执行水平。这将导致UAC提示为您的应用程序启动,就会出现,并导致以提升的权限运行所有子进程,无需额外提示

This does mean the UAC prompt will come up and will need to be acknowledged by the user: if this is undesirable (for example because it would happen in the middle of a lengthy process), you'll need to run your entire host process with elevated permissions by embedding the appropriate manifest in your application to require the 'highestAvailable' execution level: this will cause the UAC prompt to appear as soon as your app is started, and cause all child processes to run with elevated permissions without additional prompting.

编辑:我看你刚才编辑你的问题指出,运行方式并没有为你工作。这真是奇怪,因为它应该(在几个生产应用程序确实对我来说)。要求父进程通过嵌入清单一定要工作,虽然有提升的权限运行。

I see you just edited your question to state that "runas" didn't work for you. That's really strange, as it should (and does for me in several production apps). Requiring the parent process to run with elevated rights by embedding the manifest should definitely work, though.

这篇关于提升进程权限编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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