如何运行其他应用程序以管理员身份在Windows XP应用程序、管理员、身份、XP

2023-09-03 01:00:10 作者:— 怺☆恆 —

我使用的应用程序清单文件中所描述的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 $从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.

更新: 另请参见this回答过类似的问题。这基本上是相同的code,只是使用的参数为好。

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