diff --git a/New-ToastNotification.ps1 b/New-ToastNotification.ps1 index c1196b9..8b6d593 100644 --- a/New-ToastNotification.ps1 +++ b/New-ToastNotification.ps1 @@ -14,7 +14,7 @@ .NOTES Filename: New-ToastNotification.ps1 - Version: 2.0.1 + Version: 2.0.2 Author: Martin Bengtsson Blog: www.imab.dk Twitter: @mwbengtsson @@ -108,6 +108,9 @@ - Modified script output of custom script for RunPackageID to pick up Program ID dynamically Added support for getting deadline date/time dynamically for applications - Configure DynamicDeadline with the Application ID + + 2.0.2 - Fixed an error in the custom protocols + - The path to the custom scripts was incomplete .LINK @@ -736,77 +739,73 @@ function Write-CustomActionRegistry() { $ActionType, [Parameter(Position="1")] [string] - $RegCommandPath = $global:CustomScriptPath + $RegCommandPath = $global:CustomScriptsPath ) Write-Log -Message "Running Write-CustomActionRegistry function: $ActionType" switch ($ActionType) { ToastReboot { # Build out registry for custom action for rebooting the device via the action button - if((Test-Path -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command") -ne $true) { - try { - New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - } - catch { - Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" - $ErrorMessage = $_.Exception.Message - Write-Log -Level Error -Message "Error message: $ErrorMessage" - } + try { + New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null } + catch { + Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" + $ErrorMessage = $_.Exception.Message + Write-Log -Level Error -Message "Error message: $ErrorMessage" + } + } ToastRunUpdateID { # Build out registry for custom action for running software update via the action button - if((Test-Path -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command") -ne $true) { - try { - New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - } - catch { - Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" - $ErrorMessage = $_.Exception.Message - Write-Log -Level Error -Message "Error message: $ErrorMessage" - } + try { + New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null } + catch { + Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" + $ErrorMessage = $_.Exception.Message + Write-Log -Level Error -Message "Error message: $ErrorMessage" + } + } ToastRunPackageID { # Build out registry for custom action for running packages and task sequences via the action button - if((Test-Path -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command") -ne $true) { - try { - New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - } - catch { - Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" - $ErrorMessage = $_.Exception.Message - Write-Log -Level Error -Message "Error message: $ErrorMessage" - } + try { + New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null } + catch { + Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" + $ErrorMessage = $_.Exception.Message + Write-Log -Level Error -Message "Error message: $ErrorMessage" + } + } ToastRunApplicationID { # Build out registry for custom action for running applications via the action button - if((Test-Path -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command") -ne $true) { - try { - New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" - New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null - } - catch { - Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" - $ErrorMessage = $_.Exception.Message - Write-Log -Level Error -Message "Error message: $ErrorMessage" - } + try { + New-Item "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name '(default)' -Value "URL:$($ActionType) Protocol" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null + $RegCommandValue = $RegCommandPath + '\' + "$($ActionType).cmd" + New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null } + catch { + Write-Log -Level Error "Failed to create the $ActionType custom protocol in HKCU\Software\Classes. Action button might not work" + $ErrorMessage = $_.Exception.Message + Write-Log -Level Error -Message "Error message: $ErrorMessage" + } + } } } @@ -1085,7 +1084,7 @@ exit 0 ######### GENERAL VARIABLES ######### # Global variables # Setting global script version -$global:ScriptVersion = "2.0.1" +$global:ScriptVersion = "2.0.2" # Setting executing directory $global:ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition # Setting global custom action script location diff --git a/ToastNotificationScript2.0.2.zip b/ToastNotificationScript2.0.2.zip new file mode 100644 index 0000000..dca1b5b Binary files /dev/null and b/ToastNotificationScript2.0.2.zip differ