本文介绍了获取错误 - 启用权限后,OpenProcess()中的访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我想获得csrss进程的可执行路径。我启用了权限,但GetLastError()函数在OpenProcess中返回错误5。我正在以管理员身份运行Visual Studio并在64位模式下编译程序,我也在使用Windows 8.感谢所有人。
Hi all, I want to get executable path of csrss process. I enabled privileges, but GetLastError() function returns error 5 in OpenProcess. I'm running Visual Studio as administrator and compiling program in 64bit mode, also I'm using Windows 8. Thanks to all.
HANDLE hcurrentProcess=GetCurrentProcess();
HANDLE hToken;
size_t error;
if (!OpenProcessToken(hcurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return nullptr;
if (CheckTokenPrivilege(hcurrentProcess, SE_DEBUG_NAME)) {
LUID luid;
if (!LookupPrivilegeValue(NULL, SE_LOAD_DRIVER_NAME, &luid))
return nullptr;
TOKEN_PRIVILEGES newState,prvsState;
DWORD length;
newState.PrivilegeCount = 1;
newState.Privileges[0].Luid = luid;
newState.Privileges[0].Attributes = 2;
AdjustTokenPrivileges(hToken, FALSE, &newState, 28, &prvsState, &length);
error = GetLastError(); //error = 0
if (error == ERROR_NOT_ALL_ASSIGNED)
return nullptr;
//OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, 876); also error 5
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 876);
error = GetLastError(); // error 5 Access is denied
}
推荐答案
这篇关于获取错误 - 启用权限后,OpenProcess()中的访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!