Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Lovingly wrenched out of ChatGPT by OldePSN00b
- #12/6/2024
- function Disable-Notifications {
- Write-Output "Disabling Notifications..."
- try {
- # Disable Toast Notifications
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Value 0 -Force
- Write-Output "ToastEnabled set to 0."
- # Ensure QuietHours key exists
- if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours")) {
- New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion" -Name "QuietHours" -Force | Out-Null
- Write-Output "Created QuietHours registry key."
- }
- # Disable Focus Assist (Alarms Only)
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "Enabled" -Value 1 -Force
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursActive" -Value 1 -Force
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursMode" -Value 2 -Force
- Write-Output "Focus Assist set to Alarms Only."
- # Disable App Notifications
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "AppDB" -Value "" -Force
- Write-Output "App-specific notifications cleared."
- # Disable Notifications via Group Policy (requires Admin)
- if (-not (Test-Path -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications")) {
- New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion" -Name "PushNotifications" -Force | Out-Null
- Write-Output "Created PushNotifications policy key."
- }
- Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotification" -Value 1 -Force
- Write-Output "Group Policy set to disable toast notifications."
- # Restart Explorer to apply changes
- Stop-Process -Name explorer -Force
- Start-Process explorer
- Write-Output "Explorer restarted to apply notification settings."
- Write-Output "Notifications Disabled."
- }
- catch {
- Write-Output "Failed to disable notifications: $_"
- }
- }
- function Enable-Notifications {
- Write-Output "Enabling Notifications..."
- try {
- # Enable Toast Notifications
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Value 1 -Force
- Write-Output "ToastEnabled set to 1."
- # Enable Focus Assist (Off)
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "Enabled" -Value 0 -Force
- Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursActive" -Value 0 -Force
- Write-Output "Focus Assist turned off."
- # Remove Group Policy restriction
- if (Test-Path -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications") {
- Remove-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotification" -ErrorAction SilentlyContinue
- Write-Output "Group Policy for toast notifications removed."
- }
- # Restart Explorer to apply changes
- Stop-Process -Name explorer -Force
- Start-Process explorer
- Write-Output "Explorer restarted to apply notification settings."
- Write-Output "Notifications Enabled."
- }
- catch {
- Write-Output "Failed to enable notifications: $_"
- }
- }
- function Disable-Sounds {
- Write-Output "Disabling Sounds..."
- try {
- # Set Sound Scheme to ".None" for "No Sounds"
- Set-ItemProperty -Path "HKCU:\AppEvents\Schemes" -Name "(Default)" -Value ".None" -Force
- Write-Output "Sound Scheme set to 'No Sounds' ('.None')."
- # Restart Explorer to apply the setting
- Stop-Process -Name explorer -Force
- Start-Process explorer
- Write-Output "Explorer restarted to apply changes."
- }
- catch {
- Write-Output "Failed to disable sounds: $_"
- }
- # Verify if .None is applied
- $currentScheme = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
- if ($currentScheme -eq ".None") {
- Write-Output "The system has successfully applied 'No Sounds' ('.None')."
- }
- else {
- Write-Output "Unexpected sound scheme value: $currentScheme"
- }
- }
- function Enable-Sounds {
- Write-Output "Enabling Sounds..."
- try {
- # Restore Default Sound Scheme
- Set-ItemProperty -Path "HKCU:\AppEvents\Schemes" -Name "(Default)" -Value ".Default" -Force
- Write-Output "Sound Scheme set to 'Default'."
- # Restart Explorer to apply the setting
- Stop-Process -Name explorer -Force
- Start-Process explorer
- Write-Output "Explorer restarted to apply changes."
- }
- catch {
- Write-Output "Failed to enable sounds: $_"
- }
- # Verify if Default is applied
- $currentScheme = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
- if ($currentScheme -eq ".Default") {
- Write-Output "The system has successfully applied the 'Default' sound scheme."
- }
- else {
- Write-Output "Unexpected sound scheme value: $currentScheme"
- }
- }
- function Test-Settings {
- Write-Output "Verifying Current Settings..."
- # Check Notifications
- $notifications = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications").ToastEnabled
- $focusAssist = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty QuietHoursMode -ErrorAction SilentlyContinue)
- # Check Sounds
- $sounds = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
- Write-Output "Notification Status: $(if ($notifications -eq 0 -and $focusAssist -eq 2) {'Disabled'} else {'Enabled'})"
- Write-Output "Sound Scheme: $(if ($sounds -eq '.None') {'No Sounds'} elseif ($sounds -eq '.Default') {'Default Sounds'} else {$sounds})"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement