CTokenPrivileges 类
此类是 TOKEN_PRIVILEGES
结构的包装器。
重要
无法在 Windows 运行时中执行的应用程序中使用此类及其成员。
语法
class CTokenPrivileges
成员
公共构造函数
名称 | 描述 |
---|---|
CTokenPrivileges::CTokenPrivileges | 构造函数。 |
CTokenPrivileges::~CTokenPrivileges | 析构函数。 |
公共方法
名称 | 描述 |
---|---|
CTokenPrivileges::Add | 向 CTokenPrivileges 对象添加一个或多个特权。 |
CTokenPrivileges::Delete | 从 CTokenPrivileges 对象中删除特权。 |
CTokenPrivileges::DeleteAll | 从 CTokenPrivileges 对象中删除所有特权。 |
CTokenPrivileges::GetCount | 返回 CTokenPrivileges 对象中的特权条目数。 |
CTokenPrivileges::GetDisplayNames | 检索 CTokenPrivileges 对象中包含的特权的显示名称。 |
CTokenPrivileges::GetLength | 返回保存由 CTokenPrivileges 对象表示的 TOKEN_PRIVILEGES 结构所需的缓冲区大小(以字节为单位)。 |
CTokenPrivileges::GetLuidsAndAttributes | 从 CTokenPrivileges 对象中检索本地唯一标识符 (LUID) 和属性标志。 |
CTokenPrivileges::GetNamesAndAttributes | 从 CTokenPrivileges 对象中检索特权名称和属性标志。 |
CTokenPrivileges::GetPTOKEN_PRIVILEGES | 返回指向 TOKEN_PRIVILEGES 结构的指针。 |
CTokenPrivileges::LookupPrivilege | 检索与给定特权名称关联的属性。 |
公共运算符
“属性” | 描述 |
---|---|
CTokenPrivileges::operator const TOKEN_PRIVILEGES * | 将值强制转换为指向 TOKEN_PRIVILEGES 结构的指针。 |
CTokenPrivileges::operator = | 赋值运算符。 |
备注
访问令牌是描述进程或线程的安全上下文的对象,分配给登录到 Windows 系统的每个用户。
访问令牌用于描述向每个用户授予的各种安全特权。 特权由一个名为本地唯一标识符 (LUID) 的 64 位数字和一个描述符字符串组成。
CTokenPrivileges
类是 TOKEN_PRIVILEGES 结构的包装器,包含 0 个或 0 个以上的特权。 可以使用提供的类方法添加、删除或查询特权。
有关 Windows 中访问控制模型的简介,请参阅 Windows SDK 中的访问控制。
要求
标头: atlsecurity.h
CTokenPrivileges::Add
向 CTokenPrivileges
访问令牌对象添加一个或多个特权。
bool Add(LPCTSTR pszPrivilege, bool bEnable) throw(...);
void Add(const TOKEN_PRIVILEGES& rPrivileges) throw(...);
参数
pszPrivilege
指向以 null 结尾的字符串的指针,该字符串指定在 WINNT.H 头文件中定义的特权的名称。
bEnable
如果为 true,则启用特权。 如果为 false,则禁用特权。
rPrivileges
对 TOKEN_PRIVILEGES 结构的引用。 特权和属性从此结构复制并添加到 CTokenPrivileges
对象中。
返回值
如果成功添加特权,则此方法的第一种形式返回 true,否则返回 false。
CTokenPrivileges::CTokenPrivileges
构造函数。
CTokenPrivileges() throw();
CTokenPrivileges(const CTokenPrivileges& rhs) throw(... );
CTokenPrivileges(const TOKEN_PRIVILEGES& rPrivileges) throw(...);
参数
rhs
要分配给新对象的 CTokenPrivileges
对象。
rPrivileges
要分配给新 CTokenPrivileges
对象的 TOKEN_PRIVILEGES 结构。
备注
可以选择使用 TOKEN_PRIVILEGES
结构或以前定义的 CTokenPrivileges
对象创建 CTokenPrivileges
对象。
CTokenPrivileges::~CTokenPrivileges
析构函数。
virtual ~CTokenPrivileges() throw();
备注
析构函数释放所有已分配的资源。
CTokenPrivileges::Delete
从 CTokenPrivileges
访问令牌对象中删除特权。
bool Delete(LPCTSTR pszPrivilege) throw();
参数
pszPrivilege
指向以 null 结尾的字符串的指针,该字符串指定在 WINNT.H 头文件中定义的特权的名称。 例如,此参数可以指定常量 SE_SECURITY_NAME 或其对应的字符串“SeSecurityPrivilege”。
返回值
如果成功删除特权,则返回 true;否则返回 false。
备注
此方法用作创建受限令牌的工具。
CTokenPrivileges::DeleteAll
从 CTokenPrivileges
访问令牌对象中删除所有特权。
void DeleteAll() throw();
注解
删除包含在 CTokenPrivileges
访问令牌对象中的所有特权。
CTokenPrivileges::GetDisplayNames
检索 CTokenPrivileges
访问令牌对象中包含的特权的显示名称。
void GetDisplayNames(CNames* pDisplayNames) const throw(...);
参数
pDisplayNames
指向 CString
对象的数组的指针。 CNames
定义为 typedef:CTokenPrivileges::CAtlArray<CString>
。
备注
参数 pDisplayNames
是指向 CString
对象的数组的指针,该数组将接收与 CTokenPrivileges
对象中包含的特权对应的显示名称。 此方法仅检索 WINNT.H 的“Defined Privileges”节中指定的特权的显示名称。
此方法检索可显示名称:例如,如果属性名称为 SE_REMOTE_SHUTDOWN_NAME,则可显示名称为“强制从远程系统关闭”。若要获取系统名称,请使用 CTokenPrivileges::GetNamesAndAttributes。
CTokenPrivileges::GetCount
返回 CTokenPrivileges
对象中的特权条目数。
UINT GetCount() const throw();
返回值
返回 CTokenPrivileges
对象中包含的特权数。
CTokenPrivileges::GetLength
返回 CTokenPrivileges
对象的长度。
UINT GetLength() const throw();
返回值
返回保存由 CTokenPrivileges
对象表示的 TOKEN_PRIVILEGES
结构所需的字节数,包括它包含的所有特权条目。
CTokenPrivileges::GetLuidsAndAttributes
从 CTokenPrivileges
对象中检索本地唯一标识符 (LUID) 和属性标志。
void GetLuidsAndAttributes(
CLUIDArray* pPrivileges,
CAttributes* pAttributes = NULL) const throw(...);
参数
pPrivileges
指向 LUID 对象的数组的指针。 CLUIDArray
是一个定义为 CAtlArray<LUID> CLUIDArray
的 typedef。
pAttributes
指向 DWORD 对象的数组的指针。 如果此参数被省略或为 NULL,则不会检索属性。 CAttributes
是一个定义为 CAtlArray <DWORD> CAttributes
的 typedef。
备注
此方法将枚举 CTokenPrivileges
访问令牌对象中包含的所有特权,并将单个 LUID 和属性标志(可选)放入数组对象中。
CTokenPrivileges::GetNamesAndAttributes
从 CTokenPrivileges
对象中检索名称和属性标志。
void GetNamesAndAttributes(
CNames* pNames,
CAttributes* pAttributes = NULL) const throw(...);
参数
pNames
指向 CString
对象的数组的指针。 CNames
是一个定义为 CAtlArray <CString> CNames
的 typedef。
pAttributes
指向 DWORD 对象的数组的指针。 如果此参数被省略或为 NULL,则不会检索属性。 CAttributes
是一个定义为 CAtlArray <DWORD> CAttributes
的 typedef。
备注
此方法将枚举 CTokenPrivileges
对象中包含的所有特权,并将名称和属性标志(可选)放入数组对象中。
此方法检索属性名称而不是可显示名称:例如,如果属性名称为 SE_REMOTE_SHUTDOWN_NAME,则系统名称为“SeRemoteShutdownPrivilege”。若要获取可显示名称,请使用 CTokenPrivileges::GetDisplayNames 方法。
CTokenPrivileges::GetPTOKEN_PRIVILEGES
返回指向 TOKEN_PRIVILEGES
结构的指针。
const TOKEN_PRIVILEGES* GetPTOKEN_PRIVILEGES() const throw(...);
返回值
返回指向 TOKEN_PRIVILEGES 结构的指针。
CTokenPrivileges::LookupPrivilege
检索与给定特权名称关联的属性。
bool LookupPrivilege(
LPCTSTR pszPrivilege,
DWORD* pdwAttributes = NULL) const throw(...);
参数
pszPrivilege
指向以 null 结尾的字符串的指针,该字符串指定在 WINNT.H 头文件中定义的特权的名称。 例如,此参数可以指定常量 SE_SECURITY_NAME 或其对应的字符串“SeSecurityPrivilege”。
pdwAttributes
指向接收属性的变量的指针。
返回值
如果成功检索属性,则返回 true,否则返回 false。
CTokenPrivileges::operator =
赋值运算符。
CTokenPrivileges& operator= (const TOKEN_PRIVILEGES& rPrivileges) throw(...);
CTokenPrivileges& operator= (const CTokenPrivileges& rhs) throw(...);
参数
rPrivileges
要分配给 CTokenPrivileges
对象的 TOKEN_PRIVILEGES 结构。
rhs
要分配给此对象的 CTokenPrivileges
对象。
返回值
返回更新的 CTokenPrivileges
对象。
CTokenPrivileges::operator const TOKEN_PRIVILEGES *
将值强制转换为指向 TOKEN_PRIVILEGES
结构的指针。
operator const TOKEN_PRIVILEGES *() const throw(...);
注解
将值强制转换为指向 TOKEN_PRIVILEGES 结构的指针。