参考http://hi.baidu.com/43755979/blog/item/3ac19711ea01bdc4a6ef3f6a.html
解决方案 »
- 将屏幕保存为图片!!
- 请高手分析一下数据库取值的判断问题
- 求Win XP DDK 写U盘程序
- 怎样获得程序运行所需要的dll?不一般的问题~难道真的没法解决的??
- 要疯了,关于ComboBox加入列项的问题
- 中文输入法何时才不再浪费国家人力资源?
- 高手们,我作了一个单文档画直线的程序,需要对话框给view的ondraw函数传一个点的坐标,该如何实现呀!先谢谢了!
- 单击CListCtrl控件中某行某列得到item,subitem不正确,item有时为-1,何故??
- 两个简单的问题??????
- 求救:一个让我无从下手的编译错误。。。
- 'IDM_ABOUTBOX' : undeclared identifier
- 请教:怎样用VC++实现生成高斯模板
BOOL WINAPI OpenProcessToken(
__in HANDLE ProcessHandle,
__in DWORD DesiredAccess,
__out PHANDLE TokenHandle
);Parameters
ProcessHandle
A handle to the process whose access token is opened. The process must have the PROCESS_QUERY_INFORMATION access permission.DesiredAccess
Specifies an access mask that specifies the requested types of access to the access token. These requested access types are compared with the discretionary access control list (DACL) of the token to determine which accesses are granted or denied. For a list of access rights for access tokens, see Access Rights for Access-Token Objects.TokenHandle
A pointer to a handle that identifies the newly opened access token when the function returns.Return Value
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
Close the access token handle returned through the TokenHandle parameter by calling CloseHandle.Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, or Windows NT Workstation.
Server
Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header
Declared in Winbase.h; include Windows.h.
Library
Use Advapi32.lib.
DLL
Requires Advapi32.dll.
BOOL WINAPI OpenProcessToken(
__in HANDLE ProcessHandle,
__in DWORD DesiredAccess,
__out PHANDLE TokenHandle
);Parameters
ProcessHandle
A handle to the process whose access token is opened. The process must have the PROCESS_QUERY_INFORMATION access permission.DesiredAccess
Specifies an access mask that specifies the requested types of access to the access token. These requested access types are compared with the discretionary access control list (DACL) of the token to determine which accesses are granted or denied. For a list of access rights for access tokens, see Access Rights for Access-Token Objects.TokenHandle
A pointer to a handle that identifies the newly opened access token when the function returns.Return Value
If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError.Res
Close the access token handle returned through the TokenHandle parameter by calling CloseHandle.Requirements
Client
Requires Windows Vista, Windows XP, Windows 2000 Professional, or Windows NT Workstation.
Server
Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header
Declared in Winbase.h; include Windows.h.
Library
Use Advapi32.lib.
DLL
Requires Advapi32.dll.
HANDLE hToken = NULL ;
LUID luid = { 0 } ;
TOKEN_PRIVILEGES NewTokenPrivileges = { 0 } ;
TOKEN_PRIVILEGES preTokenPrivileges = { 0 } ;
DWORD dwRetLen = 0 ; __try
{
bRet = OpenProcessToken(GetCurrentProcess() , TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY , &hToken ) ;
if (!bRet)
__leave ; bRet = LookupPrivilegeValue(NULL , SE_DEBUG_NAME, &luid ) ;
if (!bRet)
__leave ; NewTokenPrivileges.PrivilegeCount = 1 ;
NewTokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
NewTokenPrivileges.Privileges[0].Luid = luid ;
bRet = AdjustTokenPrivileges(hToken , FALSE , &NewTokenPrivileges , sizeof(preTokenPrivileges) ,
&preTokenPrivileges , &dwRetLen) ;
if (!bRet)
__leave ;
}
__finally
{
if (hToken)
{
CloseHandle(hToken) ;
hToken = NULL ;
}
} return bRet ;
{
HANDLE hToken = NULL ; //令牌句柄
BOOL bRet = FALSE; //返回执行结果
TOKEN_PRIVILEGES tp = {1, {0, 0, SE_PRIVILEGE_ENABLED}}; //填充权限令牌结构 LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid); //查询是否具有调试权限
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken); //打开进程权限令牌
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof tp, 0, 0); //为进程申请 DEBUG 权限
bRet = (GetLastError() == ERROR_SUCCESS); //检测是否执行成功
return bRet;
}
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken))
{
if(LookupPrivilegeValue(NULL,SE_DEBUG_NAME,&tp.Privileges[0].Luid))
{
AdjustTokenPrivileges(hToken,FALSE,&tp,NULL,NULL,0);
}
}
if(hToken)
CloseHandle(hToken);
}打开的token不用时要CloseHandle。
//********************提升进程权限*****************************//
HANDLE hToken;
if ( OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&hToken) )
{
TOKEN_PRIVILEGES tkp;
LookupPrivilegeValue( NULL,SE_DEBUG_NAME,&tkp.Privileges[0].Luid ); //修改进程权限
tkp.PrivilegeCount=1;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges( hToken,FALSE,&tkp,sizeof tkp,NULL,NULL ); //通知系统修改进程权限
}
//*************************************************************//