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 ...
随机推荐
- Django版本更新(升级)到指定版本的命令
- Vue2 实现时空穿梭框功能模块
前言 这篇文章主要是分享一个时空穿梭框功能,也就是我们平时用的选择功能.勾选了的项就会进入到另一个框中. 时空穿梭框之旅 示例演示: 这个时空穿梭框实现了: 1.可以全选.反选 2.没有选中时,不可以 ...
- jquery 选项卡切换
html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- ios添加-webkit-overflow-scrolling依然卡顿
项目由vue-cli2创建 在overflow: auto区域内滑动ios手机出现卡顿,搜索资料后添加-webkit-overflow-scrolling: touch ios bug: 1.滑动区域 ...
- JavaSE---Annotation
1.概述 1.1 JDK1.5开始,java提供了对Annotation的支持: 1.2 Annotation其实就是 代码中的特殊标记,这些标记 可以在编译.类加载.运行时被读取,并执行相应的处理: ...
- Hashtable、HashMap、TreeMap、ConcurrentHashMap、ConcurrentSkipListMap区别
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11444013.html 并发场景下的Map容器使用场景 如果对数据有强一致要求,则需使用Hashtab ...
- 【leetcode】519. Random Flip Matrix
题目如下: You are given the number of rows n_rows and number of columns n_cols of a 2D binary matrix whe ...
- Vue学习笔记【31】——Vue路由(computed计算属性的使用)
computed计算属性的使用 默认只有getter的计算属性: <div id="app"> <input type="text" ...
- djangorestframework-jwt产生对方token
第一步是 通过jwt组件获得当前用户的token 第二步是 进行加密规则 需要用到base64模块进行加密 第三步 进行解密 按照规定的header payload signature 这种方式解密 ...
- ribbon学习
spring cloud 中的负载均衡有ribbon和feign 引入ribbon依赖 <!--ribbon相关--> <dependency> <groupId> ...