This commit is contained in:
Ondrej Sebela 2021-01-28 08:35:03 +01:00 committed by GitHub
commit 7482111111
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 155 additions and 121 deletions

View file

@ -788,7 +788,13 @@ function Write-CustomActionRegistry() {
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"
# to be able to run vbs from Toast Notification (https://www.windows10forums.com/threads/custom-protocol-handler-does-not-work-in-ms-edge-in-win10.14698/)
# 0x210000 is join of these values:
# FTA_OpenIsSafe - 0x00010000
# FTA_SafeForElevation - 0x00200000
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762506(v=vs.85).aspx
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'EditFlags' -Value '0x210000' -PropertyType Dword -Force -ErrorAction SilentlyContinue | Out-Null
$RegCommandValue = "wscript.exe $RegCommandPath\ToastRunScriptWithoutGUI.vbs" + " " + $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 {
@ -803,7 +809,13 @@ function Write-CustomActionRegistry() {
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"
# to be able to run vbs from Toast Notification (https://www.windows10forums.com/threads/custom-protocol-handler-does-not-work-in-ms-edge-in-win10.14698/)
# 0x210000 is join of these values:
# FTA_OpenIsSafe - 0x00010000
# FTA_SafeForElevation - 0x00200000
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762506(v=vs.85).aspx
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'EditFlags' -Value '0x210000' -PropertyType Dword -Force -ErrorAction SilentlyContinue | Out-Null
$RegCommandValue = "wscript.exe $RegCommandPath\ToastRunScriptWithoutGUI.vbs" + " " + $RegCommandPath + '\' + "$($ActionType).ps1"
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
}
catch {
@ -818,7 +830,13 @@ function Write-CustomActionRegistry() {
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"
# to be able to run vbs from Toast Notification (https://www.windows10forums.com/threads/custom-protocol-handler-does-not-work-in-ms-edge-in-win10.14698/)
# 0x210000 is join of these values:
# FTA_OpenIsSafe - 0x00010000
# FTA_SafeForElevation - 0x00200000
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762506(v=vs.85).aspx
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'EditFlags' -Value '0x210000' -PropertyType Dword -Force -ErrorAction SilentlyContinue | Out-Null
$RegCommandValue = "wscript.exe $RegCommandPath\ToastRunScriptWithoutGUI.vbs" + " " + $RegCommandPath + '\' + "$($ActionType).ps1"
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
}
catch {
@ -833,7 +851,13 @@ function Write-CustomActionRegistry() {
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"
# to be able to run vbs from Toast Notification (https://www.windows10forums.com/threads/custom-protocol-handler-does-not-work-in-ms-edge-in-win10.14698/)
# 0x210000 is join of these values:
# FTA_OpenIsSafe - 0x00010000
# FTA_SafeForElevation - 0x00200000
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762506(v=vs.85).aspx
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'EditFlags' -Value '0x210000' -PropertyType Dword -Force -ErrorAction SilentlyContinue | Out-Null
$RegCommandValue = "wscript.exe $RegCommandPath\ToastRunScriptWithoutGUI.vbs" + " " + $RegCommandPath + '\' + "$($ActionType).ps1"
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)\shell\open\command" -Name '(default)' -Value $RegCommandValue -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
}
catch {
@ -842,6 +866,27 @@ function Write-CustomActionRegistry() {
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
}
#FIXME ToastRunPSBase64 I added in different branch, so just for you to know how to set its RegCommandValue
ToastRunPSBase64 {
# Build out registry for custom action for running PowerShell command encoded as Base64 via the action button
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
# to be able to run vbs from Toast Notification (https://www.windows10forums.com/threads/custom-protocol-handler-does-not-work-in-ms-edge-in-win10.14698/)
# 0x210000 is join of these values:
# FTA_OpenIsSafe - 0x00010000
# FTA_SafeForElevation - 0x00200000
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb762506(v=vs.85).aspx
New-ItemProperty -LiteralPath "HKCU:\Software\Classes\$($ActionType)" -Name 'EditFlags' -Value '0x210000' -PropertyType Dword -Force -ErrorAction SilentlyContinue | Out-Null
$RegCommandValue = "wscript.exe $RegCommandPath\ToastRunScriptWithoutGUI.vbs" + " " + "`"%1`"" # %1 in quotes because it contains equal sign, which will be otherwise removed
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"
}
}
}
}
@ -853,7 +898,7 @@ function Write-CustomActionScript() {
[CmdletBinding()]
param (
[Parameter(Position="0")]
[ValidateSet("ToastRunApplicationID","ToastRunPackageID","ToastRunUpdateID","ToastReboot")]
[ValidateSet("ToastRunApplicationID", "ToastRunPackageID", "ToastRunUpdateID", "ToastReboot", "ToastRunScriptWithoutGUI")]
[string] $Type,
[Parameter(Position="1")]
[String] $Path = $global:CustomScriptsPath
@ -862,34 +907,6 @@ function Write-CustomActionScript() {
switch ($Type) {
# Create custom scripts for running software updates via the action button
ToastRunUpdateID {
try {
$CMDFileName = $Type + '.cmd'
$CMDFilePath = $Path + '\' + $CMDFileName
try {
New-item -Path $Path -Name $CMDFileName -Force -OutVariable PathInfo | Out-Null
}
catch {
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$GetCustomScriptPath = $PathInfo.FullName
[String]$Script = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File `"$global:CustomScriptsPath\ToastRunUpdateID.ps1`""
if (-NOT[string]::IsNullOrEmpty($Script)) {
Out-File -FilePath $GetCustomScriptPath -InputObject $Script -Encoding ASCII -Force
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$PS1FileName = $Type + '.ps1'
$PS1FilePath = $Path + '\' + $PS1FileName
@ -967,34 +984,6 @@ exit 0
# Previously this was hard coded to '*', making it work for task sequences only. Now also works for regular packages (only one program).
# Create custom scripts to run packages and task sequences directly from the action button
ToastRunPackageID {
try {
$CMDFileName = $Type + '.cmd'
$CMDFilePath = $Path + '\' + $CMDFileName
try {
New-item -Path $Path -Name $CMDFileName -Force -OutVariable PathInfo | Out-Null
}
catch {
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$GetCustomScriptPath = $PathInfo.FullName
[String]$Script = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File `"$global:CustomScriptsPath\ToastRunPackageID.ps1`""
if (-NOT[string]::IsNullOrEmpty($Script)) {
Out-File -FilePath $GetCustomScriptPath -InputObject $Script -Encoding ASCII -Force
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$PS1FileName = $Type + '.ps1'
$PS1FilePath = $Path + '\' + $PS1FileName
@ -1038,35 +1027,6 @@ exit 0
}
# Create custom scripts to run applications directly from the action button
ToastRunApplicationID {
try {
$CMDFileName = $Type + '.cmd'
$CMDFilePath = $Path + '\' + $CMDFileName
try {
New-item -Path $Path -Name $CMDFileName -Force -OutVariable PathInfo | Out-Null
}
catch {
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$GetCustomScriptPath = $PathInfo.FullName
[String]$Script = "powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File `"$global:CustomScriptsPath\ToastRunApplicationID.ps1`""
if (-NOT[string]::IsNullOrEmpty($Script)) {
Out-File -FilePath $GetCustomScriptPath -InputObject $Script -Encoding ASCII -Force
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
}
catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$PS1FileName = $Type + '.ps1'
$PS1FilePath = $Path + '\' + $PS1FileName
@ -1113,13 +1073,87 @@ exit 0
# Do not run another type; break
Break
}
ToastRunScriptWithoutGUI {
try {
$VBSFileName = 'ToastRunScriptWithoutGUI.vbs'
try {
New-Item -Path $Path -Name $VBSFileName -Force -OutVariable PathInfo | Out-Null
} catch {
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
try {
$GetCustomScriptPath = $PathInfo.FullName
[String]$Script = @'
Set WshShell = WScript.CreateObject("WScript.Shell")
' regex to distinguish ps1 scripts
Set runPs1 = New RegExp
With runPs1
.Pattern = "\.ps1$"
.IgnoreCase = True
.Global = False
End With
' regex to distinguish base64
Set runBase64 = New RegExp
With runBase64
.Pattern = "^toastrunpsbase64:"
.IgnoreCase = True
.Global = False
End With
If Wscript.Arguments.Count < 1 Or Wscript.Arguments.Count > 2 Then
wscript.echo "ERROR, you have to enter one or two argument(s)! First has to be the path to cmd file to run and voluntarily second one as CMDs file argument"
ElseIf Wscript.Arguments.Count = 1 Then
If runPs1.Test( WScript.Arguments(0) ) Then
' it is ps1 script
WshShell.Run "cmd /c powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File" & " " & """" & WScript.Arguments(0) & """", 0, True
ElseIf runBase64.Test( WScript.Arguments(0) ) Then
' it is base64 string
'remove part before : from passed string to get just base64
base64 = WScript.Arguments(0)
base64 = Mid(base64,instr(base64,":")+1)
WshShell.Run "cmd /c powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -EncodedCommand" & " " & """" & base64 & """", 0, True
Else
' it is something else
WshShell.Run """" & WScript.Arguments(0) & """", 0, True
End If
ElseIf Wscript.Arguments.Count = 2 Then
'wscript.echo WScript.Arguments(0)
'wscript.echo WScript.Arguments(1)
If runPs1.Test( WScript.Arguments(0) ) Then
' it is ps1 script
WshShell.Run "cmd /c powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File" & " " & """" & WScript.Arguments(0) & """" & " " & """" & WScript.Arguments(1) & """", 0, True
Else
' it isn't ps1 script
WshShell.Run """" & WScript.Arguments(0) & """" & """" & WScript.Arguments(1) & """", 0, True
End If
End If
Set WshShell = Nothing
'@
if (-NOT[string]::IsNullOrEmpty($Script)) {
Out-File -FilePath $GetCustomScriptPath -InputObject $Script -Encoding ASCII -Force
}
} catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
} catch {
Write-Log -Level Error "Failed to create the custom .cmd script for $Type. Action button might not work"
$ErrorMessage = $_.Exception.Message
Write-Log -Level Error -Message "Error message: $ErrorMessage"
}
}
}
}
######### GENERAL VARIABLES #########
# Global variables
# Setting global script version
$global:ScriptVersion = "2.1.0"
$global:ScriptVersion = "2.1.6"
# Setting executing directory
$global:ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Setting global custom action script location
@ -1629,6 +1663,7 @@ if ($CreateScriptsProtocolsEnabled -eq "True") {
Write-CustomActionScript -Type ToastRunApplicationID
Write-CustomActionScript -Type ToastRunPackageID
Write-CustomActionScript -Type ToastRunUpdateID
Write-CustomActionScript -Type ToastRunScriptWithoutGUI
New-ItemProperty -Path $global:RegistryPath -Name $RegistryName -Value $global:ScriptVersion -PropertyType "String" -Force | Out-Null
}
catch {

View file

@ -12,7 +12,6 @@
<Option Name="ADPasswordExpirationText" Enabled="False" /> <!-- Adds an additional group to the toast with text -->
<Option Name="ADPasswordExpirationDays" Value="90" /> <!-- How many days in advance shall the toast start reminding the users -->
<Option Name="RunPackageID" Enabled="False" Value="KR100907" /> <!-- Will enable the toast to run any ConfigMgr PackageID through a custom protocol -->
<Option Name="RunApplicationID" Enabled="False" Value="ScopeId_A9117680-D054-482B-BC97-532E6CBD0E6B/Application_fd55f35c-4e34-4490-a3ec-ee0b79233ec6" /> <!-- Will enable the toast to run any ConfigMgr ApplicationID through a custom protocol -->
<Option Name="RunUpdateID" Enabled="False" Value="4561600" /> <!-- Will enable the toast to run any ConfigMgr Update ID through a custom protocol. Configure the value to the relevant KB-article ID -->
<Option Name="RunUpdateTitle" Enabled="False" Value="" /> <!-- Will enable the toast to run any ConfigMgr Update Name through a custom protocol -->
<Option Name="Deadline" Enabled="False" Value="30-09-2019 08:00" /> <!-- Adds an additional group to the toast with text about the deadline of the OSUpgrade -->
@ -28,7 +27,7 @@
<Option Name="DismissButton" Enabled="False" /> <!-- Enables or disables the dismiss button. -->
<Option Name="SnoozeButton" Enabled="False" /> <!-- Enabling this option will always enable action button and dismiss button -->
<Option Name="Scenario" Type="alarm" /> <!-- Possible values are: reminder | short | long -->
<Option Name="Action1" Value="ToastReboot:" /> <!-- Action taken when using the Action button. Can be any protocol in Windows -->
<Option Name="Action1" Value="ToastRunApplicationID:ScopeId_5197DD71-3116-4878-A26C-EA6155A28E9B/Application_91b60d2e-720e-46b4-8da9-5b56f9ff0177" /> <!-- Action taken when using the Action button. Can be any protocol in Windows -->
<Option Name="Action2" Value="https://imab.dk" /> <!-- Action taken when using the Action button. Can be any protocol in Windows -->
<Text Option="GreetGivenName" Enabled="True" /> <!-- Displays the toast with a personal greeting using the users given name retrieved from AD. Will try retrieval from WMI of no local AD -->
<Text Option="MultiLanguageSupport" Enabled="False" /> <!-- Enable support for multiple languages. If set to True, the toast notification will look for the users language culture within the config file -->