【问题标题】:System service privilege to get process information in Windows 7在 Windows 7 中获取进程信息的系统服务权限
【发布时间】:2011-01-04 05:16:26
【问题描述】:

我正在尝试使用系统服务权限在 Windows 7 中获取窗口的标题及其进程名称和进程 ID,但是失败了。

如何使用open process通过系统服务权限获取进程信息?

【问题讨论】:

  • 1.什么是“系统服务特权”? 2. 你所说的“失败”是什么意思? 3.什么是“开放进程”?您是在尝试从窗口还是从进程句柄获取进程信息?

标签: windows visual-c++ windows-7 pid


【解决方案1】:

要获取其他进程信息,您必须为您的程序启用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;
}

【讨论】:

  • 如果 OP 真的将他的程序作为服务运行,那么这个答案是不相关的,因为以 SYSTEM 运行的服务默认启用 SeDebugPrivilege
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-25
  • 2014-10-12
  • 2022-06-17
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
相关资源
最近更新 更多