我正在尝试编写一个WriteProcessMemory程序,但是我需要调整我的权限才能成功地打开进程的内存。但我不知道是怎么回事。我在谷歌上搜索了几个小时,找到了一段代码,但我仍然卡住了。我在网上找到的代码:
BOOL isOK;
HANDLE hToken;
HANDLE hCurrentProcess;
hCurrentProcess = GetCurrentProcess(); // 1
isOK = OpenProcessToken( hCurrentProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken );
SetPrivilege( hToken, SE_DEBUG_NAME, TRUE );"SetPrivilege“带来了"Error C3861:"SetPrivilege":Identifier not found”我该如何启用SE_DEBUG_NAME特权?欢迎任何帮助!
发布于 2014-01-06 02:02:51
该函数不是Win32 API函数。最有可能的是下面的MSDN示例中的这个函数:http://msdn.microsoft.com/en-us/library/windows/desktop/aa446619.aspx
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "cmcfg32.lib")
BOOL SetPrivilege(
HANDLE hToken, // access token handle
LPCTSTR lpszPrivilege, // name of privilege to enable/disable
BOOL bEnablePrivilege // to enable or disable privilege
)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if ( !AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) )
{
printf("AdjustTokenPrivileges error: %u\n", GetLastError() );
return FALSE;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
printf("The token does not have the specified privilege. \n");
return FALSE;
}
return TRUE;
}我不能确定此函数与您正在使用的代码示例的作者所使用的函数相同。我建议您重新阅读该代码示例,看看是否可以找到缺少的链接。
https://stackoverflow.com/questions/20936842
复制相似问题