Search code examples
installationinno-setupterminal-services

How do I detect whether I'm installing on a Terminal Server in an InnoSetup script?


My setup should behave slightly differently when the program is installed on a Terminal Server. I know about GetSystemMetrics(SM_REMOTESESSION) but as far as I understood that will only tell me whether I'm running inside a RDP session. It would not catch the case where the server admin is logged on locally to install software, or would it?

Checking for the Terminal Server service does not appear to be viable either as that also runs on workstations when Remote Desktop has been enabled. I need to differentiate this from a true TS that allows multiple concurrent logon sessions.

Isn't there any other service or registry key that I check for?


Solution

  • Thanks to the link provided by Magnus Skog I discovered that InnoSetup already supports the GetWindowsVersionEx API function. Therefore all I had to do was this:

    function IsRunningOnTS: Boolean;
    var
      lWinVer: TWindowsVersion;
    begin
      GetWindowsVersionEx(lWinVer);
      Result := (lWinVer.SuiteMask and VER_SUITE_TERMINAL) <> 0;
    end;
    

    I have successfully tested this for the following scenarios:

    • logged on locally to an XP workstation with RDP enabled (returns False)
    • logged on remotely to a Terminal Server via RDP (returns True)
    • logged on remotely to a workstation via RDP (returns False)

    I did not yet have the opportunity to test while logged on locally on a TS. Will update this post when I have.