管理进程如何在登录用户中打开应用程序?
How can an admin process open an application in the logged in user?
概览
The Process
exe/dll 在 C++ 中编译为 运行
场景
- 登录 (win 7) 标准用户帐户(无管理员)
- 运行
The Process
作为管理员
The Process
使用 ShellExecute 打开一些应用程序 (exe)
问题
应用程序在管理员用户范围内打开
期待中
应用在标准用户范围内打开
解决方案
1。 CreateProcessAsUser
使用 CreateProcessAsUser (假设我设法获得 hToken
应该已经解决问题的权利)。
但是,我收到调用失败的消息,错误代码为 1314 - ERROR_PRIVILEGE_NOT_HELD。回到文档告诉我:
If this function fails with ERROR_PRIVILEGE_NOT_HELD (1314), use the
CreateProcessWithLogonW function instead
所以我深入研究并发现这个 CreateProcessAsUser Error 1314 不是很有用。
2。模拟登录用户
使用 ImpersonateLoggedOnUser 生成相同的错误代码:1314 - ERROR_PRIVILEGE_NOT_HELD.
3。 CreateProcessWithLogonW
CreateProcessWithLogonW 需要 lpPassword
而我自然没有
问题
管理进程如何在登录用户中打开应用程序?
这实际上是您要完成的一项非常棘手的任务。有非常严格的安全政策,这使得它非常困难。
据我所知,您可以使用 psexec 来完成。它有一个命令行开关,允许用户交互,但 运行 进程作为管理员。我认为您的命令应如下所示:
psexec \target-computer -i -s [your command]
另一种方法是使用 WMI。但为此您需要更改目标机器的安全设置(可能使用 GPO)。您需要使用模拟级别 deletgate
连接到目标机器,请参阅 here. Additionally as said before, you Need to Change the security Settings. See here
您是否尝试过使用 CreateProcessWithTokenW
which is mentioned in the CreateProcessWithLogonW
documentation? It seems to require a much weaker privilege than CreateProcessAsUser
, one you should posses (SE_IMPERSONATE_NAME
而不是 SE_ASSIGNPRIMARYTOKEN_NAME
)。
你说你已经有了交互式用户的令牌,所以我不会再谈了。
(注意:所有这些都报告了奇怪的错误,包括 CreateProcessWithTokenW
。不要放弃第一次尝试。错误和修复例如:why is CreateProcessWithTokenW failing with ERROR_ACCESS_DENIED)
hToken
不是 "right"。这是一个 token. What the error says is that you lack a privilege.
享有特权不是基本权利!默认情况下,某些权限会授予某些用户。其他需要通过Local Security Policy (in the "User Right Assignment" node in the MMC snap-in or with LsaAddAccountRights
- all of which is documented in the page Assigning Privileges to an Account).
给出
除此之外,有时您必须使用 AdjustTokenPrivileges
. This is documented in the sibling page Changing Privileges in a Token.
启用 权限
一些 API 如果您持有它们,则会启用它们。其他人不这样做,并要求您自己这样做。显而易见的方法是在调用之前启用特权,并且 API 记录为需要它。
MS 论坛 link 可能不是,但错误消息非常清楚。 MSDN 对函数的描述:
Typically, the process that calls the CreateProcessAsUser
function must have the SE_INCREASE_QUOTA_NAME privilege
and may require the SE_ASSIGNPRIMARYTOKEN_NAME privilege
if the token is not assignable.
错误是(来自您 link 进入的页面!):
ERROR_PRIVILEGE_NOT_HELD
1314 (0x522)
A required privilege is not held by the client.
概览
The Process
exe/dll 在 C++ 中编译为 运行
场景
- 登录 (win 7) 标准用户帐户(无管理员)
- 运行
The Process
作为管理员 The Process
使用 ShellExecute 打开一些应用程序 (exe)
问题
应用程序在管理员用户范围内打开
期待中
应用在标准用户范围内打开
解决方案
1。 CreateProcessAsUser
使用 CreateProcessAsUser (假设我设法获得 hToken
应该已经解决问题的权利)。
但是,我收到调用失败的消息,错误代码为 1314 - ERROR_PRIVILEGE_NOT_HELD。回到文档告诉我:
If this function fails with ERROR_PRIVILEGE_NOT_HELD (1314), use the CreateProcessWithLogonW function instead
所以我深入研究并发现这个 CreateProcessAsUser Error 1314 不是很有用。
2。模拟登录用户
使用 ImpersonateLoggedOnUser 生成相同的错误代码:1314 - ERROR_PRIVILEGE_NOT_HELD.
3。 CreateProcessWithLogonW
CreateProcessWithLogonW 需要 lpPassword
而我自然没有
问题
管理进程如何在登录用户中打开应用程序?
这实际上是您要完成的一项非常棘手的任务。有非常严格的安全政策,这使得它非常困难。
据我所知,您可以使用 psexec 来完成。它有一个命令行开关,允许用户交互,但 运行 进程作为管理员。我认为您的命令应如下所示:
psexec \target-computer -i -s [your command]
另一种方法是使用 WMI。但为此您需要更改目标机器的安全设置(可能使用 GPO)。您需要使用模拟级别 deletgate
连接到目标机器,请参阅 here. Additionally as said before, you Need to Change the security Settings. See here
您是否尝试过使用 CreateProcessWithTokenW
which is mentioned in the CreateProcessWithLogonW
documentation? It seems to require a much weaker privilege than CreateProcessAsUser
, one you should posses (SE_IMPERSONATE_NAME
而不是 SE_ASSIGNPRIMARYTOKEN_NAME
)。
你说你已经有了交互式用户的令牌,所以我不会再谈了。
(注意:所有这些都报告了奇怪的错误,包括 CreateProcessWithTokenW
。不要放弃第一次尝试。错误和修复例如:why is CreateProcessWithTokenW failing with ERROR_ACCESS_DENIED)
hToken
不是 "right"。这是一个 token. What the error says is that you lack a privilege.
享有特权不是基本权利!默认情况下,某些权限会授予某些用户。其他需要通过Local Security Policy (in the "User Right Assignment" node in the MMC snap-in or with LsaAddAccountRights
- all of which is documented in the page Assigning Privileges to an Account).
除此之外,有时您必须使用 AdjustTokenPrivileges
. This is documented in the sibling page Changing Privileges in a Token.
一些 API 如果您持有它们,则会启用它们。其他人不这样做,并要求您自己这样做。显而易见的方法是在调用之前启用特权,并且 API 记录为需要它。
MS 论坛 link 可能不是,但错误消息非常清楚。 MSDN 对函数的描述:
Typically, the process that calls the CreateProcessAsUser function must have the SE_INCREASE_QUOTA_NAME privilege and may require the SE_ASSIGNPRIMARYTOKEN_NAME privilege if the token is not assignable.
错误是(来自您 link 进入的页面!):
ERROR_PRIVILEGE_NOT_HELD
1314 (0x522)
A required privilege is not held by the client.