透過 Windows 登錄機碼變更 Windows 中的聲音方案

透過 Windows 登錄機碼變更 Windows 中的聲音方案

如何透過編輯註冊表將現有使用者的聲音方案變更為「無聲音」?我正在製作一個 .reg 文件,其中包含在新安裝的 Windows 上所需的所有調整,但我一直堅持更改聲音方案。

答案1

改變方案相對容易。但是,您必須申請新方案涉及的內容更多一些。

「無聲音」計畫的名稱為.None:你可以透過探索看到這一點HKEY_CURRENT_USER\AppEvents\Schemes\Names

所選方案為HKEY_CURRENT_USER\AppEvents\Schemes,預設為.Default。因此,您可以透過將其變更為來設定所選方案.None

New-ItemProperty -Path HKCU:\AppEvents\Schemes -Name "(Default)" -Value ".None" -Force | Out-Null

這將(技術上)設定選定的方案,您可以透過前往聲音設定來驗證該方案並查看該No Sounds方案是否已選擇。然而,事件聲音仍然會播放,這是因為所選方案尚未被選取。應用

要應用聲音方案,適當的操作是:

  • 對於每個應用程式事件匹配HKEY_CURRENT_USER\AppEvents\Schemes\Apps\*\*,將新方案名稱的子項複製到名為 的子項上.Current

例如,要將「無聲音」方案套用至系統感嘆號事件,您可以HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\SystemExclamation\.None複製HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\SystemExclamation\.Current.

但是,在您的情況下,您可以清除所有值,因為您正在套用「無聲音」主題。這可以透過一行程式碼來完成:

Get-ChildItem -Path "HKCU:\AppEvents\Schemes\Apps" | Get-ChildItem | Get-ChildItem | Where-Object {$_.PSChildName -eq ".Current"} | Set-ItemProperty -Name "(Default)" -Value ""

一步步:

  • Get-ChildItem -Path "HKCU:\AppEvents\Schemes\Apps"獲取所有應用程式。
  • Get-ChildItem獲取所有應用程式事件。
  • Get-ChildItem取得每個方案的所有應用程式事件聲音設定。
  • Where-Object {$_.PSChildName -eq ".Current"}選擇目前應用的所有應用程式事件聲音設定。
  • Set-ItemProperty -Name "(Default)" -Value ""清除這些聲音設定。

更詳細一點:

下面的鍵似乎HKEY_CURRENT_USER\AppEvents\Schemes\Apps是應用程序,其預設值是顯示字串。我的系統上有.Default(「Windows」)、Explorer(「檔案總管」)和sapisvr(「語音辨識」)。

每個應用程式鍵下的鍵是該應用程式的應用程式事件。

每個應用程式事件鍵下的鍵是為每個聲音方案播放的聲音。HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\SystemExclamation\.None使用無聲音方案時 Windows 系統感嘆號播放的聲音也是如此,HKEY_CURRENT_USER\AppEvents\Schemes\Apps\.Default\SystemExclamation\.Default使用 Windows 預設方案時 Windows 系統感嘆號播放的聲音也是如此。

此外,.Current這個關卡還有一個關鍵,那就是實際播放的聲音。據推測,當您在 UI 中選擇新方案時,它會單獨複製每個設定以覆寫該.Current值。

答案2

我剛剛創建了這個腳本。使用風險自負;

if (-Not (Test-Path 'HKCU:\AppEvents\Schemes\Names\.None'))
{ 
    New-Item -Path 'HKCU:\AppEvents\Schemes\Names' -Name '.None'
    New-ItemProperty -Path 'HKCU:\AppEvents\Schemes\Names\.None' -Name '(Default)' -Type 'String' -Value 'No Sounds'
}

Get-ChildItem -Path 'HKCU:\AppEvents\Schemes\Apps\.Default' | Select Name | ForEach-Object {
    $thing = $_.Name -replace "HKEY_CURRENT_USER", "HKCU:"
    $fullnun = "$thing\.None"
    if (-Not (Test-Path $thing))
    {
        New-Item -Path $thing -Name '.None'
        echo "$thing\.None created"
    } else {
        echo "$thing\.None already existed"
    }

    if (Test-Path($fullnun))
    {
        New-ItemProperty -Path $fullnun -Name '(Default)' -Type 'String' -Value ''
    }
}

Set-ItemProperty -Path 'hkcu:\AppEvents\Schemes' -Name "(Default)" -Type "String" -Value ".None"

答案3

這是我將聲音方案設定為“無聲音”的程式碼

Write-Host " Setting Sound Schemes to 'No Sound' .." -foregroundcolor Gray -backgroundcolor black

$Path = "HKCU:\AppEvents\Schemes"

$Keyname = "(Default)"

$SetValue = ".None"

$TestPath = Test-Path $Path
if (-Not($TestPath -eq $True)) {
   Write-Host " Creating Folder.. " -foregroundcolor Gray -backgroundcolor black
   New-item $path -force
}

if (Get-ItemProperty -path $Path -name $KeyName -EA SilentlyContinue) {

   $Keyvalue = (Get-ItemProperty -path $Path).$keyname

   if ($KeyValue -eq $setValue) {

       Write-Host " The Registry Key Already Exists. " -foregroundcolor green -backgroundcolor black


   }
   else {

       Write-Host " Changing Key Value.. " -foregroundcolor Gray -backgroundcolor black

       New-itemProperty -path $Path -Name $keyname -value $SetValue -force # Set 'No Sound' Schemes
       Get-ChildItem -Path "HKCU:\AppEvents\Schemes\Apps" | # Apply 'No Sound' Schemes
        Get-ChildItem |
        Get-ChildItem |
        Where-Object { $_.PSChildName -eq ".Current" } |
        Set-ItemProperty -Name "(Default)" -Value ""

       Write-Host " The Registry Key Value Changed Sucessfully. " -foregroundcolor green -backgroundcolor black
   }

}
else {

   Write-Host " Creating Registry Key.. " -foregroundcolor Gray -backgroundcolor black

   New-itemProperty -path $Path -Name $keyname -value $SetValue -force
   Get-ChildItem -Path "HKCU:\AppEvents\Schemes\Apps" |
       Get-ChildItem |
       Get-ChildItem |
       Where-Object { $_.PSChildName -eq ".Current" } |
       Set-ItemProperty -Name "(Default)" -Value ""


   Write-Host " The Registry Key Created Sucessfully. " -foregroundcolor green -backgroundcolor black
}

相關內容