如何降低子进程的权限
我知道如何从进程中启动具有管理员权限的进程:
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
其中 proc 是 System.Diagnostics.Process。 但如何做相反的事呢?
如果您所在的进程已经提升,如何在没有管理员权限的情况下启动新进程? 更准确地说,我们需要以与 Windows 资源管理器相同的权限级别启动新进程,因此如果禁用 UAC,则不会有任何变化,但如果启用 UAC,但我们的进程正在提升运行,我们需要在未提升的情况下执行某些操作因为我们正在创建一个虚拟驱动器,如果它是使用提升的权限创建的,并且 Windows 资源管理器在未提升的情况下运行,则它不会显示。
请随意将标题更改为更好的标题,我无法想出一个好的描述。
I know how to launch a process with Admin privileges from a process using:
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.Verb = "runas";
where proc is a System.Diagnostics.Process. But how does one do the opposite?
If the process you're in is already elevated, how do you launch the new process without admin privileges? More accurately, we need to launch the new process with the same permission level as Windows Explorer, so no change if UAC is disabled, but if UAC is enabled, but our process is running elevated, we need to perform a certain operation un-elevated because we're creating a virtual drive and if it's created with elevated permissions and Windows explorer is running unelevated it won't show up.
Feel free to change the title to something better, I couldn't come up with a good description.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的解决方案是使用 EXPLORER.exe 进程。
这个想法是使用 Windows 的文件资源管理器进程
explorer.exe
(信息)。假设我们要启动的进程位于 $TEMP\MyUnElevatedProcess.exe 上。
因此,对于 NSIS 代码,我将只写:(但可以用任何语言运行)
示例代码(使用 NSIS 安装程序)
***代码取自 http://mdb-blog.blogspot.com/2013/01/nsis -lunch-program-as-user-from-uac.html
The solution for you is to use EXPLORER.exe process.
The idea is to run the process in UN-ELEVATED mode, using windows's file explorer process
explorer.exe
(info).Lets say the process that we want to launch is on
$TEMP\MyUnElevatedProcess.exe
.So, for NSIS code, I will just write: (but can be run in ANY language)
Example code (using NSIS installer)
***code taken from http://mdb-blog.blogspot.com/2013/01/nsis-lunch-program-as-user-from-uac.html
我们最终使用了此代码项目文章中的示例:高海拔可能对您不利应用程序:如何在安装结束时启动非提升进程
到目前为止似乎有效,我收集它注入到 RunDll32.exe 中,我的 C++/Win32 相当弱,所以我也没有看实际实现的内容很多,只是使用。 确认它可以在 Vista 和 Win7 以及 x86 和 x64 中运行(至少对我们来说,x86 和 x64 需要不同的 dll,在安装时检查并使用正确的 dll)。
We ended up using the sample from this Code Project article: High elevation can be bad for your application: How to start a non-elevated process at the end of the installation
It seems to work so far, I gather it injects into RunDll32.exe, my C++/Win32 is fairly weak so I didn't look too much into the actual implementation, just it's use. Confirmed that it works in Vista and Win7 both x86 and x64 (at least for us, x86 and x64 require different dll's which is checked for at install time and the proper one is used).
Raymond Chen 在他的博客中解决了这个问题:
如何从提升的进程启动未提升的进程,反之亦然?
在 GitHub 中搜索此代码的 C# 版本,我在 Microsoft 的 Node 中找到了以下实现适用于 Visual Studio 的 .js 工具存储库:SystemUtilities.cs(
ExecuteProcessUnElevated
函数)。以防万一文件消失,文件内容如下:
Raymond Chen addressed this in his blog:
How can I launch an unelevated process from my elevated process and vice versa?
Searching in GitHub for a C# version of this code, I found the following implementation in Microsoft's Node.js tools for Visual Studio repository: SystemUtilities.cs (the
ExecuteProcessUnElevated
function).Just in case the file disappears, here's the file's contents:
如果您想从提升的进程启动未提升的进程,您可以复制 shell 进程的访问令牌并使用它来启动新进程。
If you want to start an unelevated process from an elevated one you could copy the access token of the shell process and use it to start a new process.
基于@NtFreX,我创建了另一个解决方案,
从当前身份获取令牌(似乎可以工作并且需要更少的代码),- 抱歉,这并不总是可以处理CreateProcessWithTokenW
失败,错误代码为 1314 - “客户端不拥有所需的权限”)并Based on @NtFreX I created another solution, that
takes the token from the current identity (seems to work and needs less code),- sorry, that doesn't always workCreateProcessWithTokenW
fails with error code 1314 - "A required privilege is not held by the client") and您可以使用 ProcessStartInfo.UserName 和 < a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.password.aspx" rel="nofollow noreferrer">ProcessStartInfo.Password 指定所需的帐户您要运行的进程。
You can use ProcessStartInfo.UserName and ProcessStartInfo.Password to specify the account you want your process to run under.