Advertisement
terrigan

NotificationSounds

Dec 6th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 6.30 KB | Source Code | 0 0
  1. #Lovingly wrenched out of ChatGPT by OldePSN00b
  2. #12/6/2024
  3. function Disable-Notifications {
  4.     Write-Output "Disabling Notifications..."
  5.  
  6.     try {
  7.         # Disable Toast Notifications
  8.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Value 0 -Force
  9.         Write-Output "ToastEnabled set to 0."
  10.  
  11.         # Ensure QuietHours key exists
  12.         if (-not (Test-Path -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours")) {
  13.             New-Item -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion" -Name "QuietHours" -Force | Out-Null
  14.             Write-Output "Created QuietHours registry key."
  15.         }
  16.  
  17.         # Disable Focus Assist (Alarms Only)
  18.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "Enabled" -Value 1 -Force
  19.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursActive" -Value 1 -Force
  20.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursMode" -Value 2 -Force
  21.         Write-Output "Focus Assist set to Alarms Only."
  22.  
  23.         # Disable App Notifications
  24.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "AppDB" -Value "" -Force
  25.         Write-Output "App-specific notifications cleared."
  26.  
  27.         # Disable Notifications via Group Policy (requires Admin)
  28.         if (-not (Test-Path -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications")) {
  29.             New-Item -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion" -Name "PushNotifications" -Force | Out-Null
  30.             Write-Output "Created PushNotifications policy key."
  31.         }
  32.         Set-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotification" -Value 1 -Force
  33.         Write-Output "Group Policy set to disable toast notifications."
  34.  
  35.         # Restart Explorer to apply changes
  36.         Stop-Process -Name explorer -Force
  37.         Start-Process explorer
  38.         Write-Output "Explorer restarted to apply notification settings."
  39.  
  40.         Write-Output "Notifications Disabled."
  41.     }
  42.     catch {
  43.         Write-Output "Failed to disable notifications: $_"
  44.     }
  45. }
  46.  
  47. function Enable-Notifications {
  48.     Write-Output "Enabling Notifications..."
  49.  
  50.     try {
  51.         # Enable Toast Notifications
  52.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "ToastEnabled" -Value 1 -Force
  53.         Write-Output "ToastEnabled set to 1."
  54.  
  55.         # Enable Focus Assist (Off)
  56.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "Enabled" -Value 0 -Force
  57.         Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -Name "QuietHoursActive" -Value 0 -Force
  58.         Write-Output "Focus Assist turned off."
  59.  
  60.         # Remove Group Policy restriction
  61.         if (Test-Path -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications") {
  62.             Remove-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\CurrentVersion\PushNotifications" -Name "NoToastApplicationNotification" -ErrorAction SilentlyContinue
  63.             Write-Output "Group Policy for toast notifications removed."
  64.         }
  65.  
  66.         # Restart Explorer to apply changes
  67.         Stop-Process -Name explorer -Force
  68.         Start-Process explorer
  69.         Write-Output "Explorer restarted to apply notification settings."
  70.  
  71.         Write-Output "Notifications Enabled."
  72.     }
  73.     catch {
  74.         Write-Output "Failed to enable notifications: $_"
  75.     }
  76. }
  77.  
  78. function Disable-Sounds {
  79.     Write-Output "Disabling Sounds..."
  80.  
  81.     try {
  82.         # Set Sound Scheme to ".None" for "No Sounds"
  83.         Set-ItemProperty -Path "HKCU:\AppEvents\Schemes" -Name "(Default)" -Value ".None" -Force
  84.         Write-Output "Sound Scheme set to 'No Sounds' ('.None')."
  85.  
  86.         # Restart Explorer to apply the setting
  87.         Stop-Process -Name explorer -Force
  88.         Start-Process explorer
  89.         Write-Output "Explorer restarted to apply changes."
  90.     }
  91.     catch {
  92.         Write-Output "Failed to disable sounds: $_"
  93.     }
  94.  
  95.     # Verify if .None is applied
  96.     $currentScheme = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
  97.     if ($currentScheme -eq ".None") {
  98.         Write-Output "The system has successfully applied 'No Sounds' ('.None')."
  99.     }
  100.     else {
  101.         Write-Output "Unexpected sound scheme value: $currentScheme"
  102.     }
  103. }
  104.  
  105. function Enable-Sounds {
  106.     Write-Output "Enabling Sounds..."
  107.  
  108.     try {
  109.         # Restore Default Sound Scheme
  110.         Set-ItemProperty -Path "HKCU:\AppEvents\Schemes" -Name "(Default)" -Value ".Default" -Force
  111.         Write-Output "Sound Scheme set to 'Default'."
  112.  
  113.         # Restart Explorer to apply the setting
  114.         Stop-Process -Name explorer -Force
  115.         Start-Process explorer
  116.         Write-Output "Explorer restarted to apply changes."
  117.     }
  118.     catch {
  119.         Write-Output "Failed to enable sounds: $_"
  120.     }
  121.  
  122.     # Verify if Default is applied
  123.     $currentScheme = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
  124.     if ($currentScheme -eq ".Default") {
  125.         Write-Output "The system has successfully applied the 'Default' sound scheme."
  126.     }
  127.     else {
  128.         Write-Output "Unexpected sound scheme value: $currentScheme"
  129.     }
  130. }
  131.  
  132. function Test-Settings {
  133.     Write-Output "Verifying Current Settings..."
  134.  
  135.     # Check Notifications
  136.     $notifications = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\PushNotifications").ToastEnabled
  137.     $focusAssist = (Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\QuietHours" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty QuietHoursMode -ErrorAction SilentlyContinue)
  138.  
  139.     # Check Sounds
  140.     $sounds = (Get-ItemProperty -Path "HKCU:\AppEvents\Schemes")."(Default)"
  141.  
  142.     Write-Output "Notification Status: $(if ($notifications -eq 0 -and $focusAssist -eq 2) {'Disabled'} else {'Enabled'})"
  143.     Write-Output "Sound Scheme: $(if ($sounds -eq '.None') {'No Sounds'} elseif ($sounds -eq '.Default') {'Default Sounds'} else {$sounds})"
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement