检查当前是否远程桌面登录
嗯...嗯...基于某些不可描述的原因, 总之需要程序不允许在远程桌面登录时运行...-_-
查了一下资料, 挺简单的, 判断GetSystemMetrics(SM_REMOTESESSION)就可以
可是又看了下官网发现, 官方居然不推荐使用这方法了: https://docs.microsoft.com/en-us/windows/win32/termserv/detecting-the-terminal-services-environment
原因是2012使用了更NB的RDP协议, 导致这个方法不起作用...-_-
幸好官网上直接给出了示例, 照抄改成pascal的版本, 如下:
复制代码
function IsRemoteable: Boolean;
var
lR: TRegistry;
lType, lGlassSessionId, lGSSize, lCurrentSessionId: DWORD;
begin
Result := False;
if GetSystemMetrics(SM_REMOTESESSION) = 0 then
Exit;
lR := TRegistry.Create(KEY_READ);
try
lR.RootKey := HKEY_LOCAL_MACHINE;
if not lR.OpenKeyReadOnly('SYSTEM\CurrentControlSet\Control\Terminal Server\') then
Exit;
lGSSize := SizeOf(lGlassSessionId);
if RegQueryValueEx(lR.CurrentKey, 'GlassSessionId', nil, @lType, PByte(@lGlassSessionId), @lGSSize) <> ERROR_SUCCESS then
Exit;
if not ProcessIdToSessionId(GetCurrentProcessId, lCurrentSessionId) then
Exit;
{相等是本地登录}
if lCurrentSessionId = lGlassSessionId then
Exit;
finally
lR.Free;
end;
Result := True;
end;
来源;https://www.cnblogs.com/lzl_17948876/p/13085867.html
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.076366901397705 seconds