How to recognize when logon fails in RDP / MSTSC?

核能气质少年 提交于 2020-07-21 05:00:10

问题


I am working on a C# implementation of RDP / MSTSC using the MsRdpClient9NotSafeForScripting class.

I need to recognize when the user logon failed due to wrong credentials.

The event OnLogonError should do the job but it doesn't fire (at least not on Server 2016), while the other events seem to work properly.

From the Microsoft documentation of OnLogonError:

LOGON_FAILED_BAD_PASSWORD (0 (0x0))

The logon failed because the logon credentials are not valid.

The behaviour (not fireing OnLogonError) is reported several times, but without solution. The once hint I found is: at codeproject:

After further testing, I found out that if connecting to a Windows 2003 server, the event is entered. But not when connecting to Win7 and newer and Win2008R2 and newer. I wonder if Microsoft removed the event functionality in newer systems?

But from the documentation of the event it should be supported

Minimum supported client Windows Vista

Minimum supported server Windows Server 2008


Edit

I downloaded mRemoteNG, which seems to be a very clean implementation of RDP. The event is not used there. But when I add it, it also never fires.

Edit2

The event seems to work when connecting to a Windows Server 2012 R2. But not for Server 2016 / 2019.


What I tried so far

  • Testing with several implemantations of the class (from MsRdpClient6NotSafeForScripting to MsRdpClient9NotSafeForScripting)
  • Testing with several settings

Questions

  • Is there any setting which could cause this event not to fire?
  • Is there any alternative to recognize a logon fail?

回答1:


Check your ComReference in project file and try setting the WrapperTool to aximp instead of tlbimp. See if AxInterop is generated after the build and test the remote desktop connection again.

It should be looking something like this

<COMReference Include="RDPCOMAPILib.dll">
    <Guid>cc802d05-ae07-4c15-b496-db9d22aa0a84</Guid>
    <VersionMajor>1</VersionMajor>
    <VersionMinor>0</VersionMinor>
    <WrapperTool>aximp</WrapperTool>
    <Lcid>0</Lcid>
    <Isolated>false</Isolated>
</COMReference>


来源:https://stackoverflow.com/questions/62530215/how-to-recognize-when-logon-fails-in-rdp-mstsc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!