如何运行其他应用程序以管理员身份在Windows XP [英] How to run another app as administrator on Windows XP

查看:223
本文介绍了如何运行其他应用程序以管理员身份在Windows XP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的应用程序清单文件中所描述的<一个href="http://stackoverflow.com/questions/2818179/how-to-force-c-app-to-run-as-administrator-on-windows-7">here有运行具有提升的权限(它需要)我的应用程序的一部分。
所以在需要时,主程序只调用使用的Process.Start小的组件,然后把手,这是需要管理员权限的任务。

I used the application manifest file as described here to have a part of my application running with elevated privileges (which it needs).
So when needed, the main program just invokes a small assembly using Process.Start which then handles the task for which admin rights are required.

不过,我该怎么办在Windows XP同样的事情?
看来XP只是忽略此清单和运行在当前用户上下文中的小部件。

However, how can I do the same thing on Windows XP?
It seems XP just ignores this manifest and runs the small assembly in the current user context.

推荐答案

以下$ C $从<一个C href="http://stackoverflow.com/questions/3268059/how-to-compile-program-that-will-launch-an-exe-as-administrator/3268472#3268472">here不正是我需要的:

The following code from here does just what I need:

ProcessStartInfo processStartInfo = new ProcessStartInfo("path", "args");
processStartInfo.Verb = "runas";

using (Process process = new Process())
{
   process.StartInfo = processStartInfo;
   process.Start();
   process.WaitForExit();
}

所以,事实上,你需要设置运行方式的ProcessStartInfo.Verb。 随着连接该清单code现在在Windows XP,Vista和7的罚款。

So in fact you need to set "runas" on ProcessStartInfo.Verb. With the attached manifest this code now works fine on Windows XP, Vista and 7.

更新:
另请参见<一个href="http://stackoverflow.com/questions/3925065/correct-way-to-deal-with-uac-in-c/3925167#3925167">this回答过类似的问题。这基本上是相同的code,只是使用的参数为好。

Update:
See also this answer to a similar question. This is basically the same code, just using arguments as well.

这篇关于如何运行其他应用程序以管理员身份在Windows XP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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