windows API 第22篇 WTSGetActiveConsoleSessionId
函数原型:
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的更多相关文章
- windows API 第13篇 MoveFileEx
上一篇介绍了MoveFile,这次分析MoveFileEx,它是MoveFile的扩展函数,功能还要更加强大些.先看定义: BOOL WINAPI MoveFileEx( _In_ LPCTS ...
- Windows API 第六篇 GetLocalTime
GetLocalTime获取系统时间信息.函数原型:VOID WINAPI GetLocalTime( __out LPSYSTEMTIME lpSystemTime ); 先来看S ...
- Windows API 第三篇
1.获得程序自身的路径: DWORD GetModuleFileName( HMODULE hModule, // handle to module LPTSTR lpFilename, // pat ...
- Windows API 第21篇 DeleteVolumeMountPoint 删除挂载点
函数原型:BOOL DeleteVolumeMountPoint( LPCTSTR lpszV ...
- Windows API 第20篇 SetVolumeMountPoint 设置卷挂载点参数错误
函数原型:BOOL SetVolumeMountPoint( IN LPCTSTR lpszVo ...
- Windows API 第20篇 GetVolumeNameForVolumeMountPoint
函数原型: BOOL GetVolumeNameForVolumeMountPoint( ...
- Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint
相关函数:HANDLE FindFirstVolumeMountPoint( ...
- windows API 第 18篇 FindFirstVolume FindNextVolume
函数定义:Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the vol ...
- Windows API 第17篇 GetLogicalDriveStrings 获取本机所有逻辑驱动器,以根目录的形式表示
函数原型:DWORD GetLogicalDriveStrings( DWORD nBufferLength, // size of buffer ...
随机推荐
- 【转】IntelliJ IDEA 2016.1.3注册破解激活
http://blog.csdn.net/c1481118216/article/details/51773674
- 五、properties编写
1.properties和yml编写对比 2.properties中文乱码解决 上面的内容输出的结果 原因 idea 默认编码是UTF-8,properties需要修改对应的编码 设置编码后的结果正常 ...
- 在迭代一个集合的时候,如何避免ConcurrentModificationException?
在遍历一个集合的时候,我们可以使用并发集合类来避免ConcurrentModificationException,比如使用CopyOnWriteArrayList,而不是ArrayList.
- python连接mongodb集群
一 安装模块pymongo pip3 install pymongo 二 创建一个MongoClient conn=MongoClient('mongodb://cbi:pass@ip1:20000, ...
- 检测ip是否通过
#!/bin/bashnetstat -an |grep "ESTABLISHED" |awk '{print $4}' |awk -F ':' '{print $1}' |sor ...
- bzoj 3251
http://www.lydsy.com/JudgeOnline/problem.php?id=3251 这道题在北京八十中的时候有人讲过.. 不过由于自己continue 写掉了一个所以调了很久. ...
- CEF的备忘笔记
CEF: Chromium Embeded Framewrok; (Chromium嵌入式框架)可以在PC(Linux,MacOS,Windows)上把Chromium的内核嵌入到应用程序的框架: ...
- [CSP-S模拟测试]:F(DP+线段树)
题目传送门(内部题49) 输入格式 第一行四个整数$n,q,a,b$.接下来$n$行每行一个整数$p_i$. 输出格式 一行一个整数表示答案. 样例 样例输入: 10 3 3 7 样例输出: 数据范围 ...
- 探索Redis设计与实现1:Redis 的基础数据结构概览
本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...
- php开发面试题---php缓存总结
php开发面试题---php缓存总结 一.总结 一句话总结: 缓存主要分本地缓存和分布式缓存两种 可以用分布式本地缓存:把那些常用的.不容易变的页面.数据都存下来 1.常用的缓存构架? 分布式本地缓存 ...