通过 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
}

相关内容