Adding Remote App File associations via PowerShell

We have a lot of RemoteApp and RDS deployments out in the field. Sometimes users want to use the RemoteApp to directly open the correctly associated applications, like .docx for Word files. When using Windows 8 or Windows 10 this can be done automatically by entering the RemoteApp Connection Default URL via the group policy found at the following location:

User Configuration -> Policies -> Administrative Templates ->Windows Components->Remote Desktop Services->RemoteApp and Desktop Connections->Specify default connection URL

This works great if all the clients are in the same domain as the RDS farm or if you are not running RemoteApps from within RDS. When running in a different domain the default File Associations are not applied because the user credentials do not match the credentials on the server-side, also Microsoft does not support deploying the default RemoteApp connections within a RDS Farm. The event log will show you the error:

The installation of the default connection has been cancelled. A default connection cannot be used on a system that is part of a Remote Desktop Services deployment. 

This does mean you can add the Default Connection via a logon script or by manually configuring the URL in the Control panel. The downside of this is that the File Associations are not added to the users register. To resolve this I’ve created a function that creates reg keys for each user to correct this. The usage of the function is pretty straight forward; all you have to do is place the .RDP file and the .ICO file on a public location(e.g. C:\Users\Public\ or a file share) and run the following command:

Add-RemoteAppDefaultProgram -RemoteAppName "Winword Remote App" -Extension ".txt" -RDPFile "C:\Users\Public\Winword Remote App.rdp" -IconFile "C:\Users\Public\Winword Remote App.ico"

The script takes an array as the Extention value, so you can add multiple extentions as such;

Add-RemoteAppDefaultProgram -RemoteAppName "Winword Remote App" -Extension ".txt",".doc",".log" -RDPFile "C:\Users\Public\Winword Remote App.rdp" -IconFile "C:\Users\Public\Winword Remote App.ico"

The script is included below, a slight warning: the script overwrites the current file association for the extention. as always, be careful, and happy powershelling!

<code>&lt;#
.SYNOPSIS

Adds a remote app to the "OpenWith" file assosciations options in Windows 8/10, useful for when using RemoteApps within RDS collections, or when RemoteApp is not fully supported.

.DESCRIPTION

Adds a remote app to the "OpenWith" file assosciations options in Windows 8/10, useful for when using RemoteApps within RDS collections, or when RemoteApp is not fully supported.

Warning: Overwrites current File Assoc settings.

.PARAMETER RemoteAppName
Specifies the RemoteApp name. Strongly advised to keep this the same as the RDCollection name (e.g. "Winword Remote App")

.PARAMETER Extension
Specifies the extension you want to make default. Allowed to specify multiple extentions. ".txt",".log"

.PARAMETER RDPFile
Specifies the .RDP file to use.

.PARAMETER IconFile
Specifies the .ICO file to use. 

.INPUTS

None. Does not accept pipeline input.

.OUTPUTS
lists created registry keys with verbose output.

.EXAMPLE

PS> Add-RemoteAppDefaultProgram -RemoteAppName "Winword Remote App" -Extension ".txt" -RDPFile "C:\Users\Public\Winword Remote App.rdp" -IconFile "C:\Users\Public\Winword Remote App.ico"


.EXAMPLE

PS> Add-RemoteAppDefaultProgram -RemoteAppName "Winword Remote App" -Extension ".txt",".doc",".log" -RDPFile "C:\Users\Public\Winword Remote App.rdp" -IconFile "C:\Users\Public\Winword Remote App.ico"


.LINK

https://www.cyberdrain.com

#>

function Add-RemoteAppDefaultProgram{
 Param(
   [Parameter(Mandatory=$true)]
   [string]$RemoteAppName,
   [Array]$Extension,
   [string]$RDPFile,
   [string]$IconFile

) #end param
$username = $Env:Username
$AppName = $RemoteAppName

foreach($ext in $Extension){
New-Item "HKCU:\Software\Classes\$($Ext)" -force -ea SilentlyContinue
New-Item "HKCU:\Software\Classes\$($Ext)\OpenWithProgIds" -force -ea SilentlyContinue 
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($Ext)\OpenWithProgIds" -Name "TSWorkspace.$($AppName)" -Value "" -PropertyType String -Force -ea SilentlyContinue;
}

#Adding Workspace to "OpenWith" registry.
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)" -force -ea SilentlyContinue 
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\Application" -force -ea SilentlyContinue
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\CurVer" -force -ea SilentlyContinue 
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\DefaultIcon" -force -ea SilentlyContinue 
new-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\shell" -force -ea SilentlyContinue 
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\shell\open" -force -ea SilentlyContinue 
New-Item "HKCU:\Software\Classes\TSWorkspace.$($AppName)\shell\open\command" -force -ea SilentlyContinue
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)" -Name "(default)" -Value "$($AppName) $($Ext)" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)" -Name "RemoteApp" -Value 1 -PropertyType DWord -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\Application" -Name "ApplicationName" -Value "$($AppName)" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\Application" -Name "ApplicationDescription" -Value "$($AppName)" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\Application" -Name "ApplicationIcon" -Value "`"$($IconFile)`",0" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\Application" -Name "ApplicationCompany" -Value "Applicaties" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\CurVer" -Name "(default)" -Value "TSWorkspace.$($AppName)" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\DefaultIcon" -Name "(default)" -Value "`"$($IconFile)`",0" -PropertyType String -Force -ea SilentlyContinue;
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\TSWorkspace.$($AppName)\shell\open\command" -Name "(default)" -Value "`"%systemroot%\system32\mstsc.exe`" /REMOTEFILE:`"%1`" `"$($RDPFile)`"" -PropertyType ExpandString -Force -ea SilentlyContinue;

}</code>
Follow me

Kelvin Tegelaar

I am a Microsoft Certified System Engineer working as the CTO of the Managed Services Provider Lime Networks B.V. in the Netherlands. I mostly enjoy automating business processes by deploying PowerShell solutions, but just have a large passion for Microsoft Technology in general.

If you want to contact me directly you can find me on twitter here, or via email: Kelvin {at} limenetworks.nl
Kelvin Tegelaar
Follow me

4 thoughts on “Adding Remote App File associations via PowerShell

  1. Marco

    Hi! Great article and thanks for sharing the script!!

    I have an issue applying the script. As first let me describe my environment deployment…

    Our customer needs an environment which has a RDS collection deployed with one RemoteDesktop resource and multiple RemoteApps resources. The idea is to connect those RemoteApps to the RemoteDesktop (in the same RDS farm), because the RemoteApps will be positioned in different network segments (with different network access restrictions).

    Now as you wrote, Microsoft doesn’t support deploying the default RemoteApp connections within a RDS farm (btw, do you have any URL to the official MS statement of this?). That’s why we get the warning you presented (The installation of the default connection has been cancelled. A default connection cannot be used on a system that is part of a Remote Desktop Services deployment) and bypassed that issue with a script Install-RADCConnection.ps1 (https://gallery.technet.microsoft.com/scriptcenter/313a95b3-a698-4bb0-9ed6-d89a47eacc72).

    Now the issue with the file associations. I tried your script and it sadly doesn’t work for me (RemoteDesktop resource is deployed of a few Windows Server 2016 (1607) VMs). I read in some articles that file associations only work by deploying the default RemoteApp connection (so not possible at all with the workaround / script we used). So my question is, on which version of Windows 10 were you able to confirm that your script succeeded and file associations do actually work?

    Thanks and regards, M

    Reply
    1. Kelvin Tegelaar Post author

      Long question, short answer: the script has been tested on Server 2012, 2016, 2019, so it should work. Do you get an error? have you copied the RDP files to a public location? Do you see item tries to open Remote Desktop when you click on the icon, or does it seem like nothing changed? Do you see the Remote App under the “Open With” option?

      Reply
      1. Marco

        No, I don’t get any errors while applying the script, the registries are written correctly, but neither the test file icon changes nor the “Open with” menu gets any new entries (it seems like it ignores the newly written registries completely)… And no, I don’t see any RemoteApp under the “Open with” menu. I copied the RDP and ICO file to SYSVOL (which must be accessible to all domain-joined VMs) and tried also locally on the RemoteDesktop itself, none worked.
        The only solution for adding a new value to the “Open with” menu is the Powershell script found at https://p0w3rsh3ll.wordpress.com/2018/11/08/about-file-associations/, but it’s not meant for RemoteApp applications and also uses different registry keys than your script…

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.