Add a script for editing app associations

This commit is contained in:
Manuel Thalmann 2023-07-26 12:45:01 +02:00
parent 4871c66e71
commit 186f6b5db7

View file

@ -0,0 +1,41 @@
New-Module {
class AppAssociations {
static $associationSelector = "/DefaultAssociations/Association";
static [string] GetSelector([string] $identifier) {
return "$([AppAssociations]::associationSelector)[Identifier='$identifier']";
}
static [xml] GetAppAssociations() {
[xml] $associations = (DISM /Online /Get-DefaultAppAssociations) | Select-Object -Skip 6 | Select-Object -SkipLast 2 | Out-String;
return $associations;
}
static SetAssociation([string] $identifier, [string] $progId, [string] $applicationName) {
$associations = [AppAssociations]::GetAppAssociations();
[System.Xml.XmlNode] $association = $null;
$candidates = $associations.SelectNodes([AppAssociations]::GetSelector($identifier));
if ($candidates.Count -eq 1) {
$association = $candidates[0];
} else {
$association = ($associations.SelectNodes([AppAssociations]::associationSelector) | Select-Object -Last 1)[0];
$association.Identifier = $identifier;
$association = $associations.AppendChild($association);
}
$association.ProgId = $progId;
$association.ApplicationName = $applicationName;
}
}
function Set-Association {
param (
[string] $Identifier,
[string] $ProgId,
[string] $ApplicationName
)
[AppAssociations]::SetAssociation($Identifier, $ProgId, $ApplicationName);
}
}