如何在 Vista (.NET) 中运行非提升版本
我有一个必须以管理员身份运行的应用程序。
该应用程序的一小部分是使用 Process.Start 启动其他应用程序。
启动的应用程序也将以管理员身份运行,但我宁愿看到它们以“普通”用户身份运行。
我该如何做到这一点?
/约翰/
I have an application that I have to run as Administrator.
One small part of that application is to start other applications with Process.Start
The started applications will also be run as administrators, but I'd rather see them run as the 'normal' user.
How do I accomplish that?
/johan/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
WinSafer API 允许以受限用户、普通用户或提升用户身份启动进程。
示例用法:
源代码:
P/Invoke 声明:
The WinSafer API's allow a process to be launched as a limited, normal, or elevated user.
Sample Usage:
Source code:
P/Invoke declarations:
来自:http://go.microsoft.com/fwlink/?LinkId=81232
以下是如何安排未提升流程的示例(同样来自同一链接)
From: http://go.microsoft.com/fwlink/?LinkId=81232
Here is an example of how to schedule the un-elevated process (again from the same link)
Raymond Chen 在他的博客中解决了这个问题:
如何从我的提升进程和副进程中启动未提升进程反之亦然?
在 GitHub 中搜索此代码的 C# 版本,我在 Microsoft 的 Visual Studio Node.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:
我有同样的要求,我找到了使用 Windows 任务计划程序服务的解决方案。
因此,首先添加
Task Scheduler Managed Wrapper
项目库 并使用此代码创建任务,将其配置为以受限用户身份运行 (td.Principal. RunLevel = TaskRunLevel.LUA;
),注册任务,运行任务,完成后删除任务。I had the same requirement and I come to the solution to use the task scheduler service from Windows.
So, first add the
Task Scheduler Managed Wrapper
library to your project and use this code to create a task, configure it to run as limited user (td.Principal.RunLevel = TaskRunLevel.LUA;
), register the task, run the task and after finish, delete the task.