Home >Database >Mysql Tutorial >【转】XP下OpenProcess( PROCESS_ALL_ACCESS...失败

【转】XP下OpenProcess( PROCESS_ALL_ACCESS...失败

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 15:06:221587browse

转自http://hi.baidu.com/1981633/item/04c78cceb3cf563399b4983b XP下OpenProcess( PROCESS_ALL_ACCESS... 失败 在编译器下调试时可以打开进程,单独运行时不行。代码来自网上。 解决方法: int AddPrivilege(const char *Name) { HANDLE hToken; TOKEN_PRI

转自http://hi.baidu.com/1981633/item/04c78cceb3cf563399b4983b

XP下OpenProcess( PROCESS_ALL_ACCESS...失败

在编译器下调试时可以打开进程,单独运行时不行。代码来自网上。
解决方法:

int   AddPrivilege(const   char   *Name) 

 HANDLE   hToken; 
 TOKEN_PRIVILEGES   tp; 
 LUID   Luid;

 if   (!OpenProcessToken(GetCurrentProcess(), 
  TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, 
  &hToken)) 
 { 
#ifdef   _DEBUG 
  printf( "OpenProcessToken   error.\n "); 
#endif 
  return   1; 
 }

 if   (!LookupPrivilegeValue(NULL,Name,&Luid)) 
 { 
#ifdef   _DEBUG 
  printf( "LookupPrivilegeValue   error.\n "); 
#endif 
  return   1; 
 }

 tp.PrivilegeCount   =   1; 
 tp.Privileges[0].Attributes   =   SE_PRIVILEGE_ENABLED; 
 tp.Privileges[0].Luid   =   Luid;

 if   (!AdjustTokenPrivileges(hToken, 
  0, 
  &tp, 
  sizeof(TOKEN_PRIVILEGES), 
  NULL, 
  NULL)) 
 { 
#ifdef   _DEBUG 
  printf( "AdjustTokenPrivileges   error.\n "); 
#endif 
  return   1; 
 }

 return   0; 



在程序起始处调用 AddPrivilege(SE_DEBUG_NAME);即可。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn