函数原型:
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. macos系统安装nginx

    MacOS系统安装软件: macos系统下没有yum和apt-get命令,要安装软件需要使用homebrew. 1.安装homebrew: 安装:/usr/bin/ruby -e "$(cu ...

  2. h5py库

    参考文献:http://docs.h5py.org/en/latest/high/dataset.html h5py文件存放数据集(dataset)和组(group). dataset类似数组类的数据 ...

  3. Python3.5-20190516-廖老师-自我笔记-匿名函数-装饰器

    当函数很简单的时候采用匿名函数很方便.

  4. 页面重置样式reset.css

    我把经常用到的一些页面重置样式归类到了一个.css文件中,这样可以减少代码冗余.当然还有其他的很多用处,比如h1~h5的样式全部统一的话,下面写东西很清晰很多. @charset 'utf-8'; h ...

  5. Mybatis缓存+配置

    mybatis提供了缓存机制减轻数据库压力,提高数据库性能 mybatis的缓存分为两级:一级缓存.二级缓存 一级缓存是SqlSession级别的缓存,缓存的数据只在SqlSession内有效 二级缓 ...

  6. restful规范面试总结

    1.url链接设计:采用https方式,有api关键字,有版本需要明确版本,请求链接用名词来表示资源,具体的操作方式采用请求方式来确定2.url响应数据设计:需要明确 状态码.错误信息.成功结果,子资 ...

  7. Shell脚本并发及并发数的控制

    https://www.jianshu.com/p/701952ffb755 正常情况下,Shell脚本是串行执行的,一条命令执行完才会执行接下来的命令.如下代码: # !/bin/bash for ...

  8. 使用nexus3.10搭建maven私有仓库

    使用nexus3.10搭建maven私有仓库-----详见如下链接-- --此贴用于笔记 https://blog.csdn.net/vipbupafeng/article/details/80232 ...

  9. 树莓派2代 B型 4核 1G内存 raspberry pi 2 model B

    树莓派技术交流群:318799602 期盼已久的PI2 已经到货,Element14版,非RS版本.诚信卖家如期发货,不会像某些淘宝卖家一样,没有货还标注现货,发货时间一拖再拖. 树莓派的最新力作!! ...

  10. Python进阶:set和dict/对象引用、可变性和垃圾回收/元类编程/迭代器和生成器

    frozenset:不可变集合,无序,不重复 dict上的特性: 1. dict的key或者set的值 都必须是可以hash的(不可变对象 都是可hash的, str, fronzenset, tup ...