Add a script for editing app associations
This commit is contained in:
parent
4871c66e71
commit
186f6b5db7
1 changed files with 41 additions and 0 deletions
41
scripts/Windows/Scripts/AppAssociations.ps1
Normal file
41
scripts/Windows/Scripts/AppAssociations.ps1
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue