我正在尝试创建一个启动需要 UI 的应用程序的进程。所以它不能在会话0中。我的想法是获取当前登录用户的winlogon.exe的进程ID。通过这种方式,我可以复制 winlogon 令牌并使用 CreateProcessAsUser 函数运行我的应用程序。到目前为止我的代码:(当需要我要运行的应用程序时调用它)
#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 以匹配活动用户的会话 ID。先谢谢了