首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取winlogon.exe的会话id和进程id

获取winlogon.exe的会话id和进程id
EN

Stack Overflow用户
提问于 2012-11-21 03:09:06
回答 1查看 3.6K关注 0票数 2

我正在尝试创建一个进程来启动一个需要UI的应用程序。所以它不能在会话0中。我的想法是获取当前登录用户的winlogon.exe的进程id。这样,我就可以复制winlogon令牌,并使用CreateProcessAsUser函数运行我的应用程序。到目前为止我的代码:(当需要运行我想要运行的应用程序时,会调用它)

代码语言:javascript
复制
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>

this function()
{
  HANDLE hProcessSnap;
  HANDLE hProcess;
  PROCESSENTRY32 pe32;
  DWORD dwPriorityClass;

  // Take a snapshot of all processes in the system.
  hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

  // Set the size of the structure before using it.
  pe32.dwSize = sizeof( PROCESSENTRY32 );

  //get the active session id
  DWORD sessionID = WTSGetActiveConsoleSessionId();

  // Now walk through the snapshot of processes
  //I want to narrow this down to processes called winlogon
  //if multiple users logged on system i want to make sure the active user
  //will get the application run the their screen
  do
  {
  // Retrieve the priority class.
    dwPriorityClass = 0;

    //here i want to compare the sessionID with session IDs of each winlogon process
    //stuck for implementation here
    //when i find a match i can use the processID to gain the token and create
    //a duplicate so it can be used in CreateAsUser function.
  }while( Process32Next( hProcessSnap, &pe32 ) );

 }

因此,基本上我需要一些帮助,将进程的快照范围缩小到"winlogon“,并迭代这些进程的会话ID以匹配活动用户的sessionID。提前感谢:d

EN

回答 1

Stack Overflow用户

发布于 2013-01-04 23:48:48

您可以使用ProcessIdToSessionId获取与"winlogon.exe“匹配的每个进程的会话ID,然后将结果与WTSGetActiveConsoleSessionId进行比较。

下面是你可以在你的循环中使用的一个片段:

代码语言:javascript
复制
if (_wcsicmp(pe32.szExeFile, L"winlogon.exe") == 0)
{
    DWORD ProcessSessionId = 0;
    ProcessIdToSessionId(pe32.th32ProcessID, &ProcessSessionId);
    if (ProcessSessionId == sessionID)
    {
        DoYourMagic(pe32.th32ProcessID);
        break;
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13480344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档