什么是执行具有管理员权限的方法,最简单的方法是什么?方法、最简单、管理员权限

2023-09-07 09:09:58 作者:记忆加温i

我目前只是叫我自己的程序中一个新的过程:

I am currently just calling my own program in a new process with:

MyProcessStartInfo.Verb = "runas";
MyProcessStartInfo.Arguments = "MyFlag";

和当过程开始时我检查的标志。如果它的存在 - 我只是执行的方法和关闭();

And when the process starts I check for the flag. If it's there – I just execute the method and Close();

不过,我宁愿做的东西,如果它可以简单地做更简约。这可能吗?

But I would rather do something more minimalistic if it could be done simply. Is that possible?

编辑:使用Vista和Windows7

Using Vista and Windows7.

推荐答案

您不能提升一个正在运行的进程。它的只是的不可能。你正在做正确的方式,通过产卵另一个进程使用提升priviledges。有没有其他的办法。

You can not elevate a running process. It's simply not possible. You are doing it the correct way, by spawning another process with elevated priviledges. There is no other way.

感谢。但我想也许有一种方式开始新的方法,新的工艺。

Thanks. but I was thinking maybe there is a way to start a method as a new process.

您可以创建一个单独的应用程序的可执行文件,有你在它的方法,那么你就不需要重新启动应用程序。你只需要启动其他程序。

You could create a separate application executable that has your method in it, then you would not need to restart your application. You would only need to start that other process.