Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easy way to register Notification App (Name and Icon) #236

Open
AnonymousPoke opened this issue Jun 25, 2024 · 0 comments
Open

Easy way to register Notification App (Name and Icon) #236

AnonymousPoke opened this issue Jun 25, 2024 · 0 comments
Assignees

Comments

@AnonymousPoke
Copy link

Easy way to register Notification App (Name and Icon)

I figured there had to be an easy way to register an application via code with PowerShell 5.1 to display a custom toast notification name/icon for BurntToast. The function below will register the filled in details into the registry under the "HKCU:\Software\Classes\AppUserModelId", but as long as the machine is not locked down, the entry also gets added into "HKCR\AppUserModelId" which makes this all possible (From what I can see).

Once you have registered your "app", simply plug in the specified app name into BurntToast and enjoy!

From many other users, this seems to work on Windows 10/11 just fine 😊

Function - Register Notification App:

Function Register-NotificationApp {
    
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true)]
        $AppID,

        [Parameter(Mandatory=$true)]
        $AppDisplayName,

        [Parameter(Mandatory=$false)]
        [int]$ShowInSettings=0,

        [Parameter(Mandatory=$false)]
        $IconPath
    )

    $CurrentUserRegPath = "HKCU:\Software\Classes\AppUserModelId"
    If (!(Test-Path $CurrentUserRegPath)) {
        New-Item -Path $CurrentUserRegPath -Force
    }

    $RegPath = Join-Path -Path $CurrentUserRegPath -ChildPath $AppID
    If (!(Test-Path $RegPath)) {
        $null = New-Item -Path $CurrentUserRegPath -Name $AppID -Force
    }

    $DisplayName = (Get-ItemProperty -Path $RegPath -Name DisplayName -ErrorAction SilentlyContinue).DisplayName
    If ($DisplayName -ne $AppDisplayName) {
        $null = New-ItemProperty -Path $RegPath -Name DisplayName -Value $AppDisplayName -PropertyType String -Force
    }

    $ShowInSettingsValue = (Get-ItemProperty -Path $RegPath -Name ShowInSettings -ErrorAction SilentlyContinue).ShowInSettings
    If ($ShowInSettingsValue -ne $ShowInSettings) {
        $null = New-ItemProperty -Path $RegPath -Name ShowInSettings -Value $ShowInSettings -PropertyType DWORD -Force
    }

    If ($IconPath -and (Test-Path $IconPath -PathType Leaf)) {
        $null = New-ItemProperty -Path $RegPath -Name IconUri -Value $IconPath -PropertyType String -Force
    }

}

Usage Example:

Register-NotificationApp -AppID "AppCompany.AppName!App" -AppDisplayName "Sample Application Name" -IconPath "C:\SampleIcon.ico"

Screenshot Example:

Archetype Counter is a PowerShell script (https://github.com/ssjshields/archetype-counter)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants