Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 检测是否有人登录到RDP连接_Delphi_Rdp - Fatal编程技术网

Delphi 检测是否有人登录到RDP连接

Delphi 检测是否有人登录到RDP连接,delphi,rdp,Delphi,Rdp,我有一个VPS运行一个应用程序。如果用户是否通过RDP登录,则应用程序将运行,但对于某些功能,需要通过RDP登录用户 有没有办法让我的Delphi应用程序检测是否有人通过RDP登录?也许一个Windows API可以做到这一点。我需要的是一种通过编程检测是否有人登录RDP的方法;该应用程序可以在有人登录或没有登录的情况下运行,但我需要检测有人实际登录的时间 谢谢 以下代码列出了通过RDP登录的用户帐户。它需要来自的单元JwaWtsApi32.pas 使用Windows、SysUtils、类、,

我有一个VPS运行一个应用程序。如果用户是否通过RDP登录,则应用程序将运行,但对于某些功能,需要通过RDP登录用户

有没有办法让我的Delphi应用程序检测是否有人通过RDP登录?也许一个Windows API可以做到这一点。我需要的是一种通过编程检测是否有人登录RDP的方法;该应用程序可以在有人登录或没有登录的情况下运行,但我需要检测有人实际登录的时间


谢谢

以下代码列出了通过RDP登录的用户帐户。它需要来自的单元JwaWtsApi32.pas

使用Windows、SysUtils、类、,
JwaWtsApi32;//https://sourceforge.net/projects/jedi-apilib/
过程FillRdpUserList(const UserList:TStrings;
const bIncludeDomain:Boolean=false;
常量服务器:字符串=“”);
类型
PWTSSessionInfo数组=^TWTSSessionInfo数组;
TWTSSessionInfo数组=WTS_会话_信息的数组[0..MAXCHAR];
变量
iIndex:整数;
pWSI:pwtssessioninfo数组;
pValue:PChar;
pCount,dwbytes返回:DWord;
hServer:THandle;
sValue,sDomain:字符串;
b连接:布尔型;
WtsInfoClass:TWSINFOCLASS;
bUserInfo:布尔型;
开始
断言(UserList NIL);
UserList.Clear;
如果是(sServer“”),则
开始
hServer:=WTSOpenServer(PChar(sServer));
如果(hServer=0),则
出口
结束{if}
else hServer:=WTS\u当前\u服务器\u句柄;
尝试
Win32Check(WtsEnumerateSessions)(hs服务器,0,1,
PWTS_会话_信息(pWSI),
p计数);
对于iIndex:=0到pCount-1 do
如果[WTSActive,WTSDisconnected]中有(pWSI^[iIndex].状态),则
开始
如果(包括领域)那么
WtsInfoClass:=WTSDomainName
else WtsInfoClass:=WTSUserName;
总线信息:=WtsInfoClass=WTSUserName;
重复
如果(WTSQuerySessionInformation,hServer,
pWSI^[iIndex]。会话ID,
WtsInfoClass,
指针(pValue),
德比泰斯接着说
开始
sValue:=小写(pValue);
WtsFreeMemory(pValue);
如果(S值“”),则
如果(WtsInfoClass=WTSDomainName),则
sDomain:=sValue+'\'
其他的
开始
使用pWSI^[iIndex]do
如果(pWinStationName“控制台”),则
开始
b已连接:=状态=WTSActive;
UserList.AddObject(sDomain+sValue,
TObject(b连接))
结束;{if}
sDomain:='';
结束;{else}
如果(WtsInfoClass=WTSDomainName),则
WtsInfoClass:=WTSUserName
else-bUserInfo:=真;
结束{if}
否则就断了;
直到(bUserInfo);
结束;{if}
最后
如果(pWSI NIL)那么
WtsFreeMemory(pWSI);
如果是(sServer“”),则
WTSCloseServer(hServer);
结束;{尝试/最终}
结束;{FillRdpUserList}

你看上去有多努力?参见f.i.@MartynA我正在寻找一个Delphi解决方案,在该页面上,您有这样一个信息:如果您查看@Jerrydoge引用的文章,这是一篇相对较新的文章,用Delphi编写该解决方案应该不难;看起来只不过是读取了几个注册表项而已。顺便说一句,你的q是不明确的。不清楚您是否在问:a)如何检测我的Delphi应用程序是否在RDP下运行;b) 我如何检测到有人通过RDP登录到运行我的应用程序的机器上;c) 其他的。是哪一个?在澄清之前,我投票决定结束这个问题。虽然有些人花时间否定这个问题,但其他人努力帮助,谢谢!:D
uses Windows, SysUtils, Classes,
     JwaWtsApi32;  // https://sourceforge.net/projects/jedi-apilib/

procedure FillRdpUserList (const UserList: TStrings;
                           const bIncludeDomain: Boolean = false;
                           const sServer: String = '');

type
    PWtsSessionInfoArray = ^TWtsSessionInfoArray;
    TWtsSessionInfoArray = array [0..MAXCHAR] of WTS_SESSION_INFO;

var
    iIndex : Integer;
    pWSI : PWtsSessionInfoArray;
    pValue : PChar;
    pCount, dwBytesReturned : DWord;
    hServer : THandle;
    sValue, sDomain : String;
    bConnected : Boolean;
    WtsInfoClass : TWtsInfoClass;
    bUserInfo : Boolean;

begin
    Assert (UserList <> NIL);

    UserList.Clear;

    if (sServer <> '') then
    begin
        hServer := WTSOpenServer (PChar (sServer));

        if (hServer = 0) then
            exit;
    end { if }
    else hServer := WTS_CURRENT_SERVER_HANDLE;

    try
        Win32Check (WtsEnumerateSessions (hServer, 0, 1,
                                          PWTS_SESSION_INFO (pWSI),
                                          pCount));
        for iIndex := 0 to pCount - 1 do
            if (pWSI^[iIndex].State in [WTSActive, WTSDisconnected]) then
            begin
                if (bIncludeDomain) then
                    WtsInfoClass := WTSDomainName
                else WtsInfoClass := WTSUserName;

                bUserInfo := WtsInfoClass = WTSUserName;

                repeat
                    if (WTSQuerySessionInformation (hServer,
                                                    pWSI^[iIndex].SessionId,
                                                    WtsInfoClass,
                                                    Pointer (pValue),
                                                    dwBytesReturned)) then
                    begin
                        sValue := LowerCase (pValue);
                        WtsFreeMemory (pValue);

                        if (sValue <> '') then
                            if (WtsInfoClass = WTSDomainName) then
                                sDomain := sValue + '\'
                            else
                            begin
                                with pWSI^[iIndex] do
                                    if (pWinStationName <> 'Console') then
                                    begin
                                        bConnected := State = WTSActive;
                                        UserList.AddObject (sDomain + sValue,
                                                            TObject (bConnected))
                                    end; { if }

                                sDomain := '';
                            end; { else }

                        if (WtsInfoClass = WTSDomainName) then
                            WtsInfoClass := WTSUserName
                        else bUserInfo := true;
                    end { if }
                    else Break;
                until (bUserInfo);
            end; { if }

    finally
        if (pWSI <> NIL) then
            WtsFreeMemory (pWSI);

        if (sServer <> '') then
            WTSCloseServer (hServer);
    end; { try / finally }
end; { FillRdpUserList }