- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我成功创建新用户,将用户添加到内置管理员组后,我想编辑新创建的用户的注册表(该程序是一个提升为管理员的程序)。我调用了NetUserAdd()
、NetLocalGroupAddMembers()
、LogonUser()
,然后最后LoadUserProfile()
所以用户的目录存在。
请原谅草率的代码,但这就是我之后要做的事情:
DuplicateTokenEx(hToken,TOKEN_ALL_ACCESS,&sa,SecurityImpersonation,TokenPrimary,&hNewToken);
ImpersonateLoggedOnUser(hNewToken);
HKEY hKey;
LSTATUS stat = RegOpenCurrentUser(KEY_READ|KEY_WRITE, &hKey);
// stat is 5 (ACCESS_DENIED) when KEY_WRITE is added, it
// returns 0 (ERROR_SUCCESS) when it's just KEY_READ
RegCloseKey(hKey);
RevertToSelf();
CloseHandle(hNewToken);
错误出现在 RegOpenCurrentUser()
行。当我要求写入该用户的 HKU 注册表时,它出错了。如果我只使用KEY_READ
这可能是我想做的吗?用户的注册表配置单元是否已创建?或者用户是否必须亲自登录才能创建它?
最终我想要做的是为新用户创建 GPO。
最佳答案
如果您已经使用 LoadUserProfile()
加载了用户配置文件,则根本不需要使用 RegOpenCurrentUser()
。您可以改为使用 PROFILEINFO
的 hProfile
字段LoadUserProfile()
返回:
hProfile
Type: HANDLEA handle to the HKEY_CURRENT_USER registry subtree.
...
When the LoadUserProfile call returns successfully, the hProfile member receives a registry key handle opened to the root of the user's subtree, opened with full access (KEY_ALL_ACCESS).
关于c - 新创建的用户上的 RegOpenCurrentUser(KEY_WRITE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40209402/
有人可以向我提供一个 RegOpenCurrentUser 的工作示例吗?它对我所做的就是返回 ERROR_INVALID_PARAMETER。 PHKEY keyCurrentUser = NULL
在我成功创建新用户,将用户添加到内置管理员组后,我想编辑新创建的用户的注册表(该程序是一个提升为管理员的程序)。我调用了NetUserAdd()、NetLocalGroupAddMembers()、L
我写了一个系统服务,我想在其中获取事件用户在HKEY_CURRENT_USER 下的一个注册表值。我写了如下代码。但是,它似乎只能获取系统级别的注册表值,无法获取事件用户的注册表值。请参阅下面的代码。
我是一名优秀的程序员,十分优秀!