函数原型:
DWORD WTSGetActiveConsoleSessionId (VOID)
先看一下原文介绍:

The WTSGetActiveConsoleSessionId function retrieves the Terminal
Services session currently attached to the physical console. The physical
console is the monitor, keyboard, and mouse. Note that it is not necessary that
Terminal Services be running for this function to succeed.

该函数可以用来获取当前活动的会话ID,有时候我们通过枚举explorer

的相关信息,来获取相关进程的信息,但windows是个多用户操作系统,当多个用户登录时会使通过枚举explorer而得到的用户信息不准确。所以应当先用WTSGetActiveConsoleSessionId获得当前会话ID,再通过枚举进程,通过比较sessionID进而得到的消息比较可靠。
例如:

 DWORD dwSessionId = WTSGetActiveConsoleSessionId();

	PWTS_PROCESS_INFO ppi = NULL;
DWORD dwProcessCount = 0; if (WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &ppi, &dwProcessCount))
{
for (int i = 0; i <dwProcessCount; i ++)
{ //任务管理器里可能出现多个explorer
if (_wcsicmp(ppi[i].pProcessName, L"explorer.exe") == 0)
{
if (ppi[i].SessionId == dwSessionId)
{
break;
}
}
} WTSFreeMemory(ppi);
} .......... .......... ..........

windows API 第22篇 WTSGetActiveConsoleSessionId的更多相关文章

  1. windows API 第13篇 MoveFileEx

    上一篇介绍了MoveFile,这次分析MoveFileEx,它是MoveFile的扩展函数,功能还要更加强大些.先看定义: BOOL WINAPI MoveFileEx( _In_     LPCTS ...

  2. Windows API 第六篇 GetLocalTime

    GetLocalTime获取系统时间信息.函数原型:VOID   WINAPI  GetLocalTime(    __out LPSYSTEMTIME lpSystemTime    ); 先来看S ...

  3. Windows API 第三篇

    1.获得程序自身的路径: DWORD GetModuleFileName( HMODULE hModule, // handle to module LPTSTR lpFilename, // pat ...

  4. Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点

    函数原型:BOOL DeleteVolumeMountPoint(                                                      LPCTSTR lpszV ...

  5. Windows API 第20篇 SetVolumeMountPoint 设置卷挂载点参数错误

    函数原型:BOOL SetVolumeMountPoint(                                                   IN   LPCTSTR lpszVo ...

  6. Windows API 第20篇 GetVolumeNameForVolumeMountPoint

    函数原型: BOOL GetVolumeNameForVolumeMountPoint(                                                        ...

  7. Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint

    相关函数:HANDLE FindFirstVolumeMountPoint(                                                               ...

  8. windows API 第 18篇 FindFirstVolume FindNextVolume

    函数定义:Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the vol ...

  9. Windows API 第17篇 GetLogicalDriveStrings 获取本机所有逻辑驱动器,以根目录的形式表示

    函数原型:DWORD GetLogicalDriveStrings(  DWORD nBufferLength,  // size of buffer                          ...

随机推荐

  1. 怎么更新 WIN10里的SMBv1协议

    控制面板 ---启用或关闭Windows功能---打开SMBv1服务:

  2. linux随笔-05

    shell脚本&定时任务 编写Shell脚本 可以将Shell终端解释器当作人与计算机硬件之间的“翻译官”. Shell脚本命令的工作方式有两种:交互式和批处理. 交互式(Interactiv ...

  3. Codeforces 360E 贪心 最短路

    题意及思路:https://blog.csdn.net/huanghongxun/article/details/49846927 在假设所有边都是最大值的情况下,如果第一个人能比第二个人先到,那就缩 ...

  4. Electron-vue实战(一)—搭建项目与安装Element UI

    Electron-vue实战—搭建项目与安装Element UI 作者:狐狸家的鱼 本文链接 GitHub:sueRimn 一.新建项目1.初始化项目打开cmd,新建一个项目,我使用的是electro ...

  5. django 框架下的路由分发

  6. 2019牛客多校第五场H - subsequence 2 拓扑

    H - subsequence 2 题意 要你使用前\(m\)个小写字母构造一个长度为\(n\)的字符串 有\(m*(m-1)/2\)个限制条件: \(c_{1} .c_{2}. len\):表示除去 ...

  7. 77 geometry process

    0 引言 记录几何方面的一些处理技术. 1 任意多边形面积计算:包含凸多边形和凹多边形 转载了JustDoIT https://www.cnblogs.com/TenosDoIt/p/4047211. ...

  8. <Jmeter入门不放弃>之<1.认识jmeter>

    大家这里参考学习的时候,我就不在这里配截图了,因为需要你打开工具根据文档自己去找,,才有印象,大家一定要启动JMeter! 一.Jmeter是什么 由 Apache 组织开发,基于JAVA压力测试工具 ...

  9. linux下lamp.sh一键配置lamp环境流程

    linux下lamp.sh一键配置lamp环境流程 一.总结 一句话总结: 2.将网站从github上clone到/data/www/网站域名/ 3.更改网站目录权限:chown -R apache: ...

  10. JAVA StringUtils方法全集

    StringUtils方法全集 org.apache.commons.lang.StringUtils中方法的操作对象是java.lang.String类型的对象,是JDK提供 的String类型操作 ...