zoukankan      html  css  js  c++  java
  • 远程登录环境检查

    基于产品需要,需要程序检测当前运行环境是否处于远程登录。查阅相关资料得知,有以下方法。

    基于SM_REMOTESESSION

    通过GetSystemMetrics(SM_REMOTESESSION)方法,该方法的介绍如下:

    int GetSystemMetrics(int nIndex); 获得指定的系统指标或者系统配置
    
    
    SM_REMOTESESSION介绍
    
    >This system metric is used in a Terminal Services environment. If the calling process is associated with a 
    >Terminal Services client session, the return value is nonzero. If the calling process is associated with the
    >Terminal Services console session, the return value is 0. 
    >Windows Server 2003 and Windows XP:  The console session is not necessarily the physical console. 
    >For more information, see WTSGetActiveConsoleSessionId.
    
    

    如果调用者处于远程连接中,函数返回非0。如果处于本地连接中,返回0。官方文档上有提到,在Win8以及随后版本以及Windows Server 2012以及随后版本,远程连接协议RDP有改进,会把远程连接视为本地连接,这种情况下,上述方法检测无效。

    基于注册表键值检测

    读取位于HKEY_LOCAL_MACHINESystemCurrentControlSetControlTerminal ServerGlassSessionId的注册表键,该键值保存本地session的ID。如果当前sessionId与此值相等,则说明是本地连接登陆,否则是远程连接登陆。

    但笔者通过远程连接,远程登陆到一台win7系统,在上述注册表位置中,没有找到 GlassSessionId内容,单独依赖注册表来判断也不准确。

    综合方法一和方法二

    先使用方法一,如果方法一返回为假,再使用方法二来判断。

    参考链接:

    1. 检查当前是否远程桌面登录
    2. Detecting the Remote Desktop Services environment
    作者:浩天之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
    Top
    收藏
    关注
    评论
  • 相关阅读:
    git 常用命令
    最近任务 && react文章列表
    markdown 常用格式API
    webpack 插件怎么写
    iframe
    重置浏览器滚动条css
    webpack4
    vscode插件开发
    vscode插件
    react router 的push replace
  • 原文地址:https://www.cnblogs.com/cherishui/p/14367297.html
Copyright © 2011-2022 走看看