函数原型:
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. Codeforces 1186F - Vus the Cossack and a Graph 模拟乱搞/欧拉回路

    题意:给你一张无向图,要求对这张图进行删边操作,要求删边之后的图的总边数 >= ceil((n + m) / 2), 每个点的度数 >= ceil(deg[i] / 2).(deg[i]是 ...

  2. python socket的长连接和短连接

    前言 socket中意为插座,属于进程间通信的一种方式.socket库隐藏了底层,让我们更好的专注于逻辑.如果短连接和长连接两概率没搞明白,会被坑的爬不起来. 短连接 一次完整的传输过程,发送方输出流 ...

  3. 【串线篇】REST风格的请求格式

    1.什么是rest 答出这两点就够了: 1.1 统一接口 rest其实是基于HTTP的,四种方式. RESTful架构风格规定,数据的元操作,即CRUD(create, read, update和de ...

  4. 虚拟机(JVM)如何加载类

    首先JVM加载类的一般流程分三步: 加载 链接 初始化 那么是否全部Java类都是这样三步走的方式加载呢?我们可以从Java的数据类型去出发.Java分基本类型和引用类型.其中按照面向对象的特性,一切 ...

  5. 转载:有好多是Elastic官方博客上的内容,具体看文档

    Elastic官方博客地址:https://blog.csdn.net/UbuntuTouch 这个地址是在CSDN上面的,看不惯CSDN网站的广告,同时官方博客讲述的也都十分详细,自己保留一份作为参 ...

  6. python--内置函数、匿名函数、递归调用

    匿名函数 有名函数: def func1(x): print(func1) 结果: <function func1 at 0x00000000005C3E18> 匿名函数: func2=l ...

  7. .net从服务端下载文件(可以断点续传)

    public void DownFile(string guid) { var fileTransfer = new FileTransfer(); var directoryPath = Path. ...

  8. PHP disk_free_space() 函数

    定义和用法 disk_free_space() 函数返回指定目录的可用空间,以字节为单位. 语法 disk_free_space(directory) 参数 描述 directory 必需.规定要检查 ...

  9. php打包下载文件

    使用前请先开启:查看下php.ini里面的extension=php_zip.dll前面的分号有没有去掉; $zip=new \ZipArchive(); $zifile = 'download/' ...

  10. crontab定时执行datax

    记录下使用crontab,datax定时同步数据遇到的问题. 1.开始使用如下配置,死活不执行.网上说crontab环境便利的问题,设置了也没反应. [root@hxjk_test_mysql_red ...