Skip to content

Commit 00fe75f

Browse files
Merge pull request #251 from silversword411/main
WIP Adding reboot scripts
2 parents f801441 + 930c833 commit 00fe75f

3 files changed

Lines changed: 466 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#Checking if ToastReboot:// protocol handler is present
2+
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -erroraction silentlycontinue | out-null
3+
$ProtocolHandler = get-item 'HKCR:\ToastReboot' -erroraction 'silentlycontinue'
4+
if (!$ProtocolHandler) {
5+
#create handler for reboot
6+
New-item 'HKCR:\ToastReboot' -force
7+
set-itemproperty 'HKCR:\ToastReboot' -name '(DEFAULT)' -value 'url:ToastReboot' -force
8+
set-itemproperty 'HKCR:\ToastReboot' -name 'URL Protocol' -value '' -force
9+
new-itemproperty -path 'HKCR:\ToastReboot' -propertytype dword -name 'EditFlags' -value 2162688
10+
New-item 'HKCR:\ToastReboot\Shell\Open\command' -force
11+
set-itemproperty 'HKCR:\ToastReboot\Shell\Open\command' -name '(DEFAULT)' -value 'C:\Windows\System32\shutdown.exe -r -t 00' -force
12+
}
13+
14+
# Check if NuGet is installed
15+
if (!(Get-PackageProvider -Name NuGet -ListAvailable)) {
16+
Write-Output "Nuget installing"
17+
Install-PackageProvider -Name NuGet -Force
18+
}
19+
else {
20+
Write-Output "Nuget already installed"
21+
}
22+
if (-not (Get-Module -Name BurntToast -ListAvailable)) {
23+
Write-Output "BurntToast installing"
24+
Install-Module -Name BurntToast -Force
25+
}
26+
else {
27+
Write-Output "BurntToast already installed"
28+
}
29+
30+
if (-not (Get-Module -Name RunAsUser -ListAvailable)) {
31+
Write-Output "RunAsUser installing"
32+
Install-Module -Name RunAsUser -Force
33+
}
34+
else {
35+
Write-Output "RunAsUser already installed"
36+
}
37+
38+
invoke-ascurrentuser -scriptblock {
39+
40+
$heroimage = New-BTImage -Source 'https://imageurl.png' -HeroImage
41+
$Text1 = New-BTText -Content "Message from Computer Dudez"
42+
$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"
43+
$Button = New-BTButton -Content "Snooze" -snooze -id 'SnoozeTime'
44+
$Button2 = New-BTButton -Content "Reboot now" -Arguments "ToastReboot:" -ActivationType Protocol
45+
$5Min = New-BTSelectionBoxItem -Id 5 -Content '5 minutes'
46+
$10Min = New-BTSelectionBoxItem -Id 10 -Content '10 minutes'
47+
$1Hour = New-BTSelectionBoxItem -Id 60 -Content '1 hour'
48+
$4Hour = New-BTSelectionBoxItem -Id 240 -Content '4 hours'
49+
$8Hour = New-BTSelectionBoxItem -Id 480 -Content '8 hours'
50+
$1Day = New-BTSelectionBoxItem -Id 1440 -Content '1 day'
51+
$Items = $5Min, $10Min, $1Hour, $4Hour, $8Hour, $1Day
52+
$SelectionBox = New-BTInput -Id 'SnoozeTime' -DefaultSelectionBoxItemId 10 -Items $Items
53+
$action = New-BTAction -Buttons $Button, $Button2 -inputs $SelectionBox
54+
$Binding = New-BTBinding -Children $text1, $text2 -HeroImage $heroimage
55+
$Visual = New-BTVisual -BindingGeneric $Binding
56+
$Content = New-BTContent -Visual $Visual -Actions $action
57+
Submit-BTNotification -Content $Content
58+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#Checking if ToastReboot:// protocol handler is present
2+
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -erroraction silentlycontinue | out-null
3+
$ProtocolHandler = get-item 'HKCR:\ToastReboot' -erroraction 'silentlycontinue'
4+
if (!$ProtocolHandler) {
5+
#create handler for reboot
6+
New-item 'HKCR:\ToastReboot' -force
7+
set-itemproperty 'HKCR:\ToastReboot' -name '(DEFAULT)' -value 'url:ToastReboot' -force
8+
set-itemproperty 'HKCR:\ToastReboot' -name 'URL Protocol' -value '' -force
9+
new-itemproperty -path 'HKCR:\ToastReboot' -propertytype dword -name 'EditFlags' -value 2162688
10+
New-item 'HKCR:\ToastReboot\Shell\Open\command' -force
11+
set-itemproperty 'HKCR:\ToastReboot\Shell\Open\command' -name '(DEFAULT)' -value 'C:\Windows\System32\shutdown.exe -r -t 00' -force
12+
}
13+
14+
# Always run the shutdown command
15+
Invoke-Expression -Command "shutdown /r /t 600"
16+
17+
# Check if NuGet is installed
18+
if (!(Get-PackageProvider -Name NuGet -ListAvailable)) {
19+
Write-Output "Nuget installing"
20+
Install-PackageProvider -Name NuGet -Force
21+
}
22+
else {
23+
Write-Output "Nuget already installed"
24+
}
25+
if (-not (Get-Module -Name BurntToast -ListAvailable)) {
26+
Write-Output "BurntToast installing"
27+
Install-Module -Name BurntToast -Force
28+
}
29+
else {
30+
Write-Output "BurntToast already installed"
31+
}
32+
33+
if (-not (Get-Module -Name RunAsUser -ListAvailable)) {
34+
Write-Output "RunAsUser installing"
35+
Install-Module -Name RunAsUser -Force
36+
}
37+
else {
38+
Write-Output "RunAsUser already installed"
39+
}
40+
41+
invoke-ascurrentuser -scriptblock {
42+
43+
$heroimage = New-BTImage -Source 'https://imageurl.png' -HeroImage
44+
$Text1 = New-BTText -Content "Message from Computer Dudez"
45+
$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"
46+
$Button = New-BTButton -Content "Snooze" -snooze -id 'SnoozeTime'
47+
$Button2 = New-BTButton -Content "Reboot now" -Arguments "ToastReboot:" -ActivationType Protocol
48+
$5Min = New-BTSelectionBoxItem -Id 5 -Content '5 minutes'
49+
$10Min = New-BTSelectionBoxItem -Id 10 -Content '10 minutes'
50+
$Items = $5Min, $10Min
51+
$SelectionBox = New-BTInput -Id 'SnoozeTime' -DefaultSelectionBoxItemId 10 -Items $Items
52+
$action = New-BTAction -Buttons $Button, $Button2 -inputs $SelectionBox
53+
$Binding = New-BTBinding -Children $text1, $text2 -HeroImage $heroimage
54+
$Visual = New-BTVisual -BindingGeneric $Binding
55+
$Content = New-BTContent -Visual $Visual -Actions $action
56+
Submit-BTNotification -Content $Content
57+
}

0 commit comments

Comments
 (0)