Skip to content

Commit

Permalink
WIP: Add reboot via toast requests
Browse files Browse the repository at this point in the history
  • Loading branch information
silversword411 committed Aug 29, 2024
1 parent 2f15cf5 commit 930c833
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
58 changes: 58 additions & 0 deletions scripts_wip/Win_Reboot_Request_via_toast.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#Checking if ToastReboot:// protocol handler is present
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -erroraction silentlycontinue | out-null
$ProtocolHandler = get-item 'HKCR:\ToastReboot' -erroraction 'silentlycontinue'
if (!$ProtocolHandler) {
#create handler for reboot
New-item 'HKCR:\ToastReboot' -force
set-itemproperty 'HKCR:\ToastReboot' -name '(DEFAULT)' -value 'url:ToastReboot' -force
set-itemproperty 'HKCR:\ToastReboot' -name 'URL Protocol' -value '' -force
new-itemproperty -path 'HKCR:\ToastReboot' -propertytype dword -name 'EditFlags' -value 2162688
New-item 'HKCR:\ToastReboot\Shell\Open\command' -force
set-itemproperty 'HKCR:\ToastReboot\Shell\Open\command' -name '(DEFAULT)' -value 'C:\Windows\System32\shutdown.exe -r -t 00' -force
}

# Check if NuGet is installed
if (!(Get-PackageProvider -Name NuGet -ListAvailable)) {
Write-Output "Nuget installing"
Install-PackageProvider -Name NuGet -Force
}
else {
Write-Output "Nuget already installed"
}
if (-not (Get-Module -Name BurntToast -ListAvailable)) {
Write-Output "BurntToast installing"
Install-Module -Name BurntToast -Force
}
else {
Write-Output "BurntToast already installed"
}

if (-not (Get-Module -Name RunAsUser -ListAvailable)) {
Write-Output "RunAsUser installing"
Install-Module -Name RunAsUser -Force
}
else {
Write-Output "RunAsUser already installed"
}

invoke-ascurrentuser -scriptblock {

$heroimage = New-BTImage -Source 'https://imageurl.png' -HeroImage
$Text1 = New-BTText -Content "Message from Computer Dudez"
$Text2 = New-BTText -Content "Updates have been installed and a reboot is needed. Please select if you'd like to reboot now, or snooze this message for later. Call if you have any questions. 867-5309"
$Button = New-BTButton -Content "Snooze" -snooze -id 'SnoozeTime'
$Button2 = New-BTButton -Content "Reboot now" -Arguments "ToastReboot:" -ActivationType Protocol
$5Min = New-BTSelectionBoxItem -Id 5 -Content '5 minutes'
$10Min = New-BTSelectionBoxItem -Id 10 -Content '10 minutes'
$1Hour = New-BTSelectionBoxItem -Id 60 -Content '1 hour'
$4Hour = New-BTSelectionBoxItem -Id 240 -Content '4 hours'
$8Hour = New-BTSelectionBoxItem -Id 480 -Content '8 hours'
$1Day = New-BTSelectionBoxItem -Id 1440 -Content '1 day'
$Items = $5Min, $10Min, $1Hour, $4Hour, $8Hour, $1Day
$SelectionBox = New-BTInput -Id 'SnoozeTime' -DefaultSelectionBoxItemId 10 -Items $Items
$action = New-BTAction -Buttons $Button, $Button2 -inputs $SelectionBox
$Binding = New-BTBinding -Children $text1, $text2 -HeroImage $heroimage
$Visual = New-BTVisual -BindingGeneric $Binding
$Content = New-BTContent -Visual $Visual -Actions $action
Submit-BTNotification -Content $Content
}
57 changes: 57 additions & 0 deletions scripts_wip/Win_Reboot_Request_via_toast_andforce.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#Checking if ToastReboot:// protocol handler is present
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -erroraction silentlycontinue | out-null
$ProtocolHandler = get-item 'HKCR:\ToastReboot' -erroraction 'silentlycontinue'
if (!$ProtocolHandler) {
#create handler for reboot
New-item 'HKCR:\ToastReboot' -force
set-itemproperty 'HKCR:\ToastReboot' -name '(DEFAULT)' -value 'url:ToastReboot' -force
set-itemproperty 'HKCR:\ToastReboot' -name 'URL Protocol' -value '' -force
new-itemproperty -path 'HKCR:\ToastReboot' -propertytype dword -name 'EditFlags' -value 2162688
New-item 'HKCR:\ToastReboot\Shell\Open\command' -force
set-itemproperty 'HKCR:\ToastReboot\Shell\Open\command' -name '(DEFAULT)' -value 'C:\Windows\System32\shutdown.exe -r -t 00' -force
}

# Always run the shutdown command
Invoke-Expression -Command "shutdown /r /t 600"

# Check if NuGet is installed
if (!(Get-PackageProvider -Name NuGet -ListAvailable)) {
Write-Output "Nuget installing"
Install-PackageProvider -Name NuGet -Force
}
else {
Write-Output "Nuget already installed"
}
if (-not (Get-Module -Name BurntToast -ListAvailable)) {
Write-Output "BurntToast installing"
Install-Module -Name BurntToast -Force
}
else {
Write-Output "BurntToast already installed"
}

if (-not (Get-Module -Name RunAsUser -ListAvailable)) {
Write-Output "RunAsUser installing"
Install-Module -Name RunAsUser -Force
}
else {
Write-Output "RunAsUser already installed"
}

invoke-ascurrentuser -scriptblock {

$heroimage = New-BTImage -Source 'https://imageurl.png' -HeroImage
$Text1 = New-BTText -Content "Message from Computer Dudez"
$Text2 = New-BTText -Content "Emergency Updates have been installed for a critical bug and a reboot is required. Please reboot now. Call if you have any questions. 867-5309"
$Button = New-BTButton -Content "Snooze" -snooze -id 'SnoozeTime'
$Button2 = New-BTButton -Content "Reboot now" -Arguments "ToastReboot:" -ActivationType Protocol
$5Min = New-BTSelectionBoxItem -Id 5 -Content '5 minutes'
$10Min = New-BTSelectionBoxItem -Id 10 -Content '10 minutes'
$Items = $5Min, $10Min
$SelectionBox = New-BTInput -Id 'SnoozeTime' -DefaultSelectionBoxItemId 10 -Items $Items
$action = New-BTAction -Buttons $Button, $Button2 -inputs $SelectionBox
$Binding = New-BTBinding -Children $text1, $text2 -HeroImage $heroimage
$Visual = New-BTVisual -BindingGeneric $Binding
$Content = New-BTContent -Visual $Visual -Actions $action
Submit-BTNotification -Content $Content
}

0 comments on commit 930c833

Please sign in to comment.