【发布时间】:2016-06-17 19:55:45
【问题描述】:
当我尝试检查某个进程是否正在使用数据执行保护 (DEP) 时,我收到错误 87 (INVALID_PARAMETER)。我检查了我的代码,它似乎没问题,但不幸的是我仍然有同样的错误。
代码:
BOOL var = true;
DWORD dwPolicy;
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, false, 3624);
if (hProc == NULL) {
cout << "Can't open Process because of the error " << GetLastError() << endl;
}
if (GetProcessDEPPolicy(hProc, &dwPolicy, 0) != FALSE) {
if (dwPolicy == PROCESS_DEP_ENABLE) {
cout << "For try.exe process data execution prevention is enabled" << endl;
}
else if (dwPolicy == NULL) {
cout << "For try.exe process data execution prevention is disabled" << endl;
}
else {
cout << "Data is thrunked and we can't change DEP value in future" << endl;
}
}
else {
cout << "There was an error with discovering DEP in try.exe process because of "<<GetLastError() << endl;
}
编译执行后得到:
There was an error with discovering DEP in try.exe process because of 87
【问题讨论】:
-
附带说明,如果
OpenProcess()失败,您不应该调用GetProcessDEPPolicy()。并且不要忘记在打开的HANDLE上致电CloseHandle()。
标签: c++ windows winapi visual-c++ visual-studio-2015