为什么使用mstscax连接到远程桌面会延迟60秒

问题描述

我过去在C#Winforms应用程序中使用过mstscax ActiveX控件。

我的PC通过WIFI路由器连接到网络。

使用我的C#应用​​程序,我单击连接按钮,60秒钟后,显示远程桌面。 使用mstsc连接同一台计算机时,它将尽快显示远程桌面。

如何解决60多岁的问题。

以下是我的c#应用程序代码的一部分

                _log.Info("Initialize new connection ...");
                MSTSCLib.imsRdpClientNonScriptable5 secured = (MSTSCLib.imsRdpClientNonScriptable5)rdp.Getocx();
                rdp.RemoteProgram.RemoteProgramMode = _rdpFile.RemoteApplicationMode == 1;

                if(rdp.RemoteProgram.RemoteProgramMode)
                {
                    rdp.AdvancedSettings.ContainerHandledFullScreen = 1;
                    secured.UseMultimon = true;
                    secured.ClearTextPassword = _msg.Credential.ClearPassword;
                    rdp.StartConnected = 1;
                    //secured.RemoteMonitorCount = 2
                    //secured.RemoteMonitorLayoutMatchesLocal = true
                    //secured.GetRemoteMonitorsBoundingBox
                    //secured.disableConnectionBar = true;
                    //secured.Clipboard
                    //secured.ConnectionBarText
                }
                else if (_rdpFile.AlternateShell != string.Empty)
                {
                    // AlternateShell is already replaced by RemoteApp in recent windows
                    // secured.ConnectionBarText = "mydesktop";
                    rdp.SecuredSettings3.StartProgram = _rdpFile.AlternateShell;
                    rdp.SecuredSettings3.workdir = _rdpFile.ShellWorkingDirectory;
                }

                rdp.MsRdpClientShell.PublicMode = true;
                //rdp.MsRdpClientShell.SetRdpProperty("use multimon",1);
                //rdp.MsRdpClientShxell.SetRdpProperty("selectedmonitors","0,1");

                //rdp.TransportSettings2.GatewayDomain = _msg.Credential.Domain;
                rdp.TransportSettings2.GatewayUsername = msg.Credential.Domain + "\\" + _msg.Credential.Username;
                rdp.TransportSettings2.GatewayPassword = _msg.Credential.ClearPassword;
                //rdp.TransportSettings4.GatewayHostname = _rdpFile.GatewayHostname.Split(':')[0];
                rdp.TransportSettings2.GatewayHostname = _rdpFile.GatewayHostname;
                _log.DebugFormat("rdp.TransportSettings4.GatewayUsername={0}",rdp.TransportSettings2.GatewayUsername);
                //Console.WriteLine(DateTime.Now.ToString() + " - rdp.TransportSettings4.GatewayPassword={0}",rdp.TransportSettings4.GatewayPassword);
                _log.DebugFormat("rdp.TransportSettings4.GatewayHostname={0}",rdp.TransportSettings2.GatewayHostname);
                rdp.TransportSettings2.GatewayUsageMethod = _rdpFile.GatewayUsageMethod;
                rdp.TransportSettings2.GatewayProfileUsageMethod = _rdpFile.GatewayProfileUsageMethod;
                rdp.TransportSettings2.GatewayCredsSource = _rdpFile.GatewayCredentialsSource;
                //rdp.TransportSettings4.GatewayUserSelectedCredsSource = 0;
                _log.DebugFormat("rdp.TransportSettings4.GatewayUsageMethod={0}",rdp.TransportSettings2.GatewayUsageMethod);
                _log.DebugFormat("rdp.TransportSettings4.GatewayProfileUsageMethod={0}",rdp.TransportSettings2.GatewayProfileUsageMethod);
                _log.DebugFormat("rdp.TransportSettings4.GatewayCredsSource={0}",rdp.TransportSettings2.GatewayCredsSource);
                _log.DebugFormat("rdp.TransportSettings4.GatewayUserSelectedCredsSource={0}",rdp.TransportSettings2.GatewayUserSelectedCredsSource);
                rdp.Server = _rdpFile.FullAddress.Split(':')[0];
                rdp.AdvancedSettings8.RDPPort = _rdpFile.ServerPort;
                rdp.AdvancedSettings8.EnableAutoReconnect = true;
                _log.DebugFormat("rdp.Server={0}",rdp.Server);
                _log.DebugFormat("rdp.AdvancedSettings9.RDPPort={0}",rdp.AdvancedSettings8.RDPPort);
                rdp.Domain = _msg.Credential.Domain;
                rdp.UserName = _msg.Credential.Username;
                rdp.AdvancedSettings8.ClearTextPassword = _msg.Credential.ClearPassword;

                //rdp.UserName = txtUserName.Text;
                //rdp.AdvancedSettings7.ClearTextPassword = txtUserName.Text;
                //rdp.AdvancedSettings7.EnableCredsspSupport = true;
                //rdp.AdvancedSettings7.PublicMode = false;

                //imsRdpClientNonScriptable7 a = (imsRdpClientNonScriptable7)rdp.Getocx();
                //a.PromptForCredsOnClient = false;
                //a.PromptForCredentials = false;

                rdp.FullScreen = true;
                rdp.DesktopWidth = System@R_879_404[email protected];
                rdp.DesktopHeight = System@R_879_404[email protected];
                if(!rdp.RemoteProgram.RemoteProgramMode)
                {
                    rdp.AdvancedSettings8.displayConnectionBar = true;
                    rdp.AdvancedSettings8.ConnectionBarShowMinimizeButton = true;
                    rdp.AdvancedSettings8.ConnectionBarShowRestoreButton = false;
                    rdp.AdvancedSettings8.ConnectionBarShowPinButton = true;
                    rdp.AdvancedSettings8.PinConnectionBar = true;
                    rdp.AdvancedSettings8.GrabFocusOnConnect = true;
                }

                //rdp.AdvancedSettings8.PluginDlls
                // REGSVR UDVC DLL
                rdp.AdvancedSettings8.PluginDlls = "{3C8458A3-2EBE-4840-BB07-3BA5BF810588}";

                if (rdp.RemoteProgram.RemoteProgramMode)
                {
                    // GXY: 2020/3/27
                    // https://docs.microsoft.com/en-us/windows/win32/termserv/imsrdpclientsecuredsettings-keyboardhookmode
                    // rdp.SecuredSettings3.KeyboardHookMode = 0;
                    // https://docs.microsoft.com/en-us/windows/win32/termserv/imsrdpclientadvancedsettings-disablectrlaltdel
                    // rdp.AdvancedSettings9.disableCtrlAltDel = 1;
                    rdp.AdvancedSettings8.HotKeyCtrlAltDel = 0;
                    rdp.AdvancedSettings8.HotKeyAltEsc = 0;
                    rdp.AdvancedSettings8.HotKeyAltShiftTab = 0;
                    rdp.AdvancedSettings8.HotKeyAltSpace = 0;
                    rdp.AdvancedSettings8.HotKeyAltTab = 0;
                    rdp.AdvancedSettings8.HotKeyFocusReleaseLeft = 0;
                    rdp.AdvancedSettings8.HotKeyFocusReleaseRight = 0;
                    rdp.AdvancedSettings8.HotKeyFullScreen = 0;
                    rdp.AdvancedSettings8.EnableWindowsKey = 0;                    
                }

                // Specifies if the display should be scaled to fit the client area of the control. 
                rdp.AdvancedSettings8.SmartSizing = true;

                //0: If Server authentication(RDSH certificate) fails,connect without warning
                rdp.AdvancedSettings8.AuthenticationLevel = 0;
                rdp.AdvancedSettings8.EnableCredsspSupport = true;

                // Specifies an interval,in milliseconds,at which the client sends keep-alive messages to the server.
                // A group policy setting that specifies whether persistent client connections to the server are allowed can override this property setting.
                rdp.AdvancedSettings8.keepAliveInterval = _appSettings.KeepAliveInterval;
                _log.DebugFormat("rdp.AdvancedSettings8.keepAliveInterval={0}",rdp.AdvancedSettings8.keepAliveInterval);

                // Specifies the minimum interval,between the sending of mouse events.
                rdp.AdvancedSettings8.minInputSendInterval = _appSettings.MinInputSendInterval;
                _log.DebugFormat("rdp.AdvancedSettings8.minInputSendInterval={0}",rdp.AdvancedSettings8.minInputSendInterval);

                // Specifies the maximum length of time,in seconds,that the client control waits for a connection to an IP address.
                // During connection,the control may attempt to connect to multiple IP addresses.
                // You can use this property in a situation where you need to disconnect an idle session; for example,in a kiosk environment.
                rdp.AdvancedSettings8.MinutesToIdleTimeout = _appSettings.MinutesToIdleTimeout;
                _log.DebugFormat("rdp.AdvancedSettings8.MinutesToIdleTimeout={0}",rdp.AdvancedSettings8.MinutesToIdleTimeout);

                // Specifies the total length of time,that the client control waits for a connection to complete. 
                rdp.AdvancedSettings8.overallConnectionTimeout = _appSettings.OverallConnectionTimeout;
                _log.DebugFormat("rdp.AdvancedSettings8.overallConnectionTimeout={0}",rdp.AdvancedSettings8.overallConnectionTimeout);

                // Specifies the maximum length of time,the control may attempt to connect to multiple IP addresses.
                rdp.AdvancedSettings8.singleConnectionTimeout = _appSettings.SingleConnectionTimeout;
                _log.DebugFormat("rdp.AdvancedSettings8.singleConnectionTimeout={0}",rdp.AdvancedSettings8.singleConnectionTimeout);

                // Specifies the length of time,to wait for the server to respond to a disconnection request.
                // If the server does not reply within the specified time,the client control disconnects.
                rdp.AdvancedSettings8.shutdownTimeout = _appSettings.ShutdownTimeout;
                _log.DebugFormat("rdp.AdvancedSettings8.shutdownTimeout={0}",rdp.AdvancedSettings8.shutdownTimeout);
                
                // Specifies if programs launched with the StartProgram property should be maximized.
                rdp.AdvancedSettings8.MaximizeShell = 1;

                // In-memory bitmap cache size in KB for 8bpp bitmaps
                rdp.AdvancedSettings8.BitmapCacheSize = _appSettings.BitmapCacheSize;
                // Bitmap cache file size in MB for 8bpp bitmaps
                rdp.AdvancedSettings8.BitmapVirtualCacheSize = _appSettings.BitmapVirtualCacheSize;
                // Bitmap cache file size in MB for 16bpp bitmaps
                rdp.AdvancedSettings8.BitmapVirtualCache16BppSize = _appSettings.BitmapVirtualCacheSize;
                // Bitmap cache file size in Mb for 24bpp bitmaps
                rdp.AdvancedSettings8.BitmapVirtualCache24BppSize = _appSettings.BitmapVirtualCacheSize;
                // Bitmap cache file size in MB for 32bpp bitmaps
                rdp.AdvancedSettings8.BitmapVirtualCache32BppSize = _appSettings.BitmapVirtualCacheSize;

                // Specifies whether bitmap caching is enabled.
                // Persistent caching can improve performance but requires additional disk space.
                rdp.AdvancedSettings8.BitmapPeristence = _appSettings.BitmapCachePersistence;

                // Specifies if persistent bitmap caching should be used.
                // Persistent caching can improve performance but requires additional disk space.
                rdp.AdvancedSettings8.BitmapPersistence = _appSettings.BitmapCachePersistence;

                // Specifies whether persistent bitmap caching should be used. 
                // Persistent caching can improve performance but requires additional disk space.
                // Bitmap caching / cache persistence active
                rdp.AdvancedSettings8.CachePersistenceActive = _appSettings.BitmapCachePersistence;

                _log.InfoFormat("Bitmapcache = {0},BitmapVirtualCacheSize = {1},CachePersistenceActive = {2}",_appSettings.BitmapCacheSize,_appSettings.BitmapVirtualCacheSize,_appSettings.BitmapCachePersistence);

                // Specifies if bandwidth changes are automatically detected.
                //rdp.AdvancedSettings8.BandwidthDetection = 1;
                // CONNECTION_TYPE_WAN (5(0x5))
                // CONNECTION_TYPE_LAN (6(0x6))
                //rdp.AdvancedSettings8.NetworkConnectionType = 0x5;

                // PerformanceFlags
                rdp.AdvancedSettings8.PerformanceFlags = TS_PERF_disABLE_WALLPAPER|TS_PERF_disABLE_THEMING|TS_PERF_disABLE_MENUANIMATIONS|TS_PERF_disABLE_CURSOR_SHADOW;
                
                if(String.IsNullOrEmpty(rdp.TransportSettings2.GatewayHostname))
                {
                    rdp.AdvancedSettings8.RedirectPrinters = true;
                }
                else
                {
                    rdp.AdvancedSettings8.RedirectPrinters = false;
                }

                rdp.AdvancedSettings8.RedirectSmartCards = true;
                rdp.AdvancedSettings8.RedirectDevices = false;
                rdp.AdvancedSettings8.RedirectDirectX = false;
                rdp.AdvancedSettings8.RedirectDrives = false;
                //rdp.AdvancedSettings9.BitmapVirtualCache32BppSize = 32;
                // rdp.AdvancedSettings9.AudioRedirectionMode =
                rdp.AdvancedSettings8.RedirectClipboard = true;
                if (Environment.Osversion.Version.Major == 6 && Environment.Osversion.Version.Minor == 1)
                {
                    if (!EnvironmentHelper.Is64BitOperatingSystem())
                    {
                        // win7 32bit does not support clipboard hook!!!
                        Console.WriteLine("disable RedirectClipboard in Win7 32bit OS.");
                        rdp.AdvancedSettings8.RedirectClipboard = false;
                    }
                }
                #endregion

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)