我正在尝试使用系统服务权限在Windows 7中获取窗口的标题及其进程名称和进程ID,但这会失败。
如何使用开放流程通过系统服务权限获取流程信息?
答案 0 :(得分:0)
要获取其他流程信息,您必须为您的计划启用SeDebugPrivilege
。
此代码将为您启用:
{
int err = 0;
int result = 0;
HANDLE token = NULL;
HANDLE proc_handle = NULL;
TOKEN_PRIVILEGES priv;
/*Get the open process handle to the process*/
proc_handle = GetCurrentProcess ();
/* Get a token for this process.*/
result = OpenProcessToken (proc_handle, TOKEN_ALL_ACCESS, &token);
if (! result)
{
/* return failure */
}
/* Get the LUID for the SeDebugPrivilege privilege.*/
result = LookupPrivilegeValue (NULL, SE_DEBUG_NAME,
&priv.Privileges[0].Luid);
if (! result)
{
err = qerr_win32toq (GetLastError ());
printf("LookupPrivilegeValue failed with err: %d", err);
goto out;
}
priv.PrivilegeCount = 1;
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
result = AdjustTokenPrivileges (token, FALSE, &priv, 0, (PTOKEN_PRIVILEGES)
NULL, 0);
if (! result)
{
err = qerr_win32toq (GetLastError ());
printf ("AdjustTokenPrivilege failed with err: %d", err);
goto out;
}
out:
if (token)
CloseHandle (token);
return err;
}