LsaAddAccountRights() 实际上并不授予帐户权限

问题描述 投票:0回答:1

完整代码:https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/Win7Samples/security/lsapolicy/lsaprivs

我运行了代码,但用户仍然没有被授予“作为服务登录”权限。

Screenshot of Administrator Powershell session

代码片段:

NTSTATUS
SetPrivilegeOnAccount(
    LSA_HANDLE PolicyHandle,    // open policy handle
    PSID AccountSid,            // SID to grant privilege to
    LPWSTR PrivilegeName,       // privilege to grant (Unicode)
    BOOL bEnable                // enable or disable
    )
{
    LSA_UNICODE_STRING PrivilegeString;

    //
    // Create a LSA_UNICODE_STRING for the privilege name.
    //
    InitLsaString(&PrivilegeString, PrivilegeName);

    //
    // grant or revoke the privilege, accordingly
    //
    if(bEnable) {
        return LsaAddAccountRights(
                PolicyHandle,       // open policy handle
                AccountSid,         // target SID
                &PrivilegeString,   // privileges
                1                   // privilege count
                );
    }
    else {
        return LsaRemoveAccountRights(
                PolicyHandle,       // open policy handle
                AccountSid,         // target SID
                FALSE,              // do not disable all rights
                &PrivilegeString,   // privileges
                1                   // privilege count
                );
    }
}
winapi
1个回答
0
投票

我必须重新启动本地安全策略应用程序。 然后我就可以看到更改生效了。

© www.soinside.com 2019 - 2024. All rights reserved.