windows 以管理员身份运行另一个程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16804103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run another program as administrator
提问by Steve Laster
So I tried Googling this and this does not get a good result. What Im trying to do is run another program as an administrator without that annoying UAC popping up everytime.
所以我尝试谷歌搜索这个,但没有得到一个好的结果。我试图做的是以管理员身份运行另一个程序,而不会每次都弹出烦人的 UAC。
The idea is this, this program requires administrator privileges to run which the user will grant. Then this program will run a bunch of other programs that also require administrator permissions. Instead of the user clicking and allowing a bunch of programs time to time, the program with admin permissions can run the other programs as administrator since itself has it.
这个想法是这样的,这个程序需要管理员权限才能运行,用户将授予该权限。然后这个程序将运行一堆也需要管理员权限的其他程序。与用户不时点击并允许一堆程序不同,具有管理员权限的程序可以以管理员身份运行其他程序,因为它自己拥有它。
This would save the user from following way to many instructions. Also, having the program request the user to allow many things looks very unprofessional. Its just a one-click program that does it all.
这将使用户免于遵循许多说明。此外,让程序要求用户允许很多事情看起来很不专业。它只是一个一键式程序,可以完成这一切。
The reason why I said Google is not getting a good result is because the page is flooded with how users can run their program AS an administrator. I want to be able to run another program as an admin.
我之所以说谷歌没有得到好的结果是因为页面上充斥着用户如何以管理员身份运行他们的程序。我希望能够以管理员身份运行另一个程序。
I was thinking of dropping the setup files on a folder and then running the files as admin from CMD but it would require me to use runas
and after testing it on myself, it kept saying that the password/username was wrong yet I was sure it was.
我正在考虑将安装文件放在一个文件夹中,然后从 CMD 以管理员身份运行这些文件,但这需要我使用,runas
并且在我自己测试后,它一直说密码/用户名错误,但我确定它是.
Any other tips?
还有其他提示吗?
回答by Matt Wilko
You can run another application from your application by using:
您可以使用以下方法从您的应用程序运行另一个应用程序:
Process.Start("Notepad.exe")
If your original program is running Elevated (As Admin), then Notepad will run As Admin (there will be no UAC prompt)
如果您的原始程序运行 Elevated (As Admin),那么记事本将以管理员身份运行(不会有 UAC 提示)
If your original program is notrunning Elevated and you want to start an application elevated (As Admin) you will have to do something like this (this will prompt for elevation):
如果您的原始程序没有运行 Elevated 并且您想启动一个提升的应用程序(作为管理员),您将必须执行以下操作(这将提示提升):
Dim procStartInfo As New ProcessStartInfo
Dim procExecuting As New Process
With procStartInfo
.UseShellExecute = True
.FileName = "Notepad.exe"
.WindowStyle = ProcessWindowStyle.Normal
.Verb = "runas" 'add this to prompt for elevation
End With
procExecuting = Process.Start(procStartInfo)
Note that there is no way to circumvent the UAC prompt. If UAC is enabled then the user will have to agree to the elevation at some point.
请注意,无法绕过 UAC 提示。如果启用了 UAC,那么用户将不得不在某个时候同意提升。