Ian Branch 127 Posted October 6, 2019 Hi Team, I need to detect if my delphi (10.3.2) app is running in a remote RDP session. I want to do the detection in the Project file so I can disable the Theme. e.g. Application.Initialize; Application.MainFormOnTaskbar := True; if not IsRemoteSession then TStyleManager.TrySetStyle('Iceberg Classico'); Thoughts/suggestions appreciated. Regards & TIA, Ian Share this post Link to post
FredS 138 Posted October 6, 2019 Detecting the Remote Desktop Services environment 1 1 Share this post Link to post
Ian Branch 127 Posted October 6, 2019 Hi Fred, Thanks for your suggestion.. Yes I have seen that and have tried a couple of things but none seem to work from the project file for one reason or another. Ian Share this post Link to post
Anders Melander 1782 Posted October 7, 2019 This works for me: function DetectRemoteSession: boolean; const SM_REMOTECONTROL = $2001; // This system metric is used in a Terminal // Services environment. Its value is nonzero // if the current session is remotely // controlled; otherwise, 0. SM_REMOTESESSION = $1000; // 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 Server console session, the // return value is 0. The console session is // not necessarily the physical console. var Mode: string; begin Result := (GetSystemMetrics(SM_REMOTESESSION) <> 0) or (GetSystemMetrics(SM_REMOTECONTROL) <> 0); // Test for emulated local/remote mode if (FindCmdLineSwitchEx('Session', Mode, ['-','\','/'], True)) then begin if (SameText(Mode, 'Remote')) then Result := True else if (SameText(Mode, 'Local')) then Result := False; end; end; 1 Share this post Link to post
David Heffernan 2345 Posted October 7, 2019 8 hours ago, Ian Branch said: but none seem to work from the project file for one reason or another Doesn't seem very plausible that this is the case. And it's tricky for us to dig deeper into "one reason or another". Share this post Link to post
Ian Branch 127 Posted October 7, 2019 Hi Anders, Thank you for your suggestion. So, this is my implementation.. program LogViewer; uses Vcl.Controls, Vcl.Forms, Vcl.Themes, Vcl.Styles, System.SysUtils, MainFrm in 'MainFrm.pas' {MainForm}; {$R *.res} function DetectRemoteSession: boolean; const SM_REMOTECONTROL = $2001; // This system metric is used in a Terminal // Services environment. Its value is nonzero // if the current session is remotely // controlled; otherwise, 0. SM_REMOTESESSION = $1000; // 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 Server console session, the // return value is 0. The console session is // not necessarily the physical console. var Mode: string; begin Result := (GetSystemMetrics(SM_REMOTESESSION) <> 0) or (GetSystemMetrics(SM_REMOTECONTROL) <> 0); // Test for emulated local/remote mode if (FindCmdLineSwitchEx('Session', Mode, ['-','\','/'], True)) then begin if (SameText(Mode, 'Remote')) then Result := True else if (SameText(Mode, 'Local')) then Result := False; end; end; begin // Application.Initialize; Application.MainFormOnTaskbar := True; if not DetectRemoteSession then TStyleManager.TrySetStyle('Iceberg Classico'); Application.CreateForm(TMainForm, MainForm); Application.Run; // end. Unfortunately, despite having vcl.controls in the uses, getsystemmetrics is still not recognised. :-( Nor does it know anything about FindCmdLineSwitchEx Thoughts/Suggestions? Regards, Ian Share this post Link to post
David Heffernan 2345 Posted October 7, 2019 GetSystemMetrics is from Winapi.Windows. Use a find in files search of the rtl/vcl source to find which unit contains specific functions. Share this post Link to post
Angus Robertson 574 Posted October 7, 2019 There is no need for the function DetectRemoteSession to be in the DPR, it can just as easily be in MainFrm.pas, just not in a method in a form. Angus Share this post Link to post
Anders Melander 1782 Posted October 7, 2019 FindCmdLineSwitchEx: Just replace it with: FindCmdLineSwitch('Session', Mode, True) or simply remove the whole block. It's just for testing. Share this post Link to post
Ian Branch 127 Posted October 7, 2019 All, Thank you for your input. Much appreciated. It is now working as desired. Regards & Tks again. Ian Share this post Link to post