
預設通訊設備 powershell。
是否可以在powershell中將音訊設備輸出設定為預設通訊設備?我需要這個,因為我在揚聲器和耳機之間切換,我已經在 powershell 中使用 AudioDeviceCmdlet 將音訊裝置設定為預設輸出。
我已經嘗試在註冊表中執行此操作,但 powershell 無法更改該特定部分中的值(我在管理員模式下運行 powershell)
有了這個我想創建一個腳本,可以看到什麼設備被關閉或打開,然後知道切換到揚聲器或我的耳機作為輸出
我已經有這個程式碼:
if((Get-PnpDevice -InstanceId 'INSTANCEID' | Select-Object -Property status) -eq "OK"){ 停用-PnpDevice -InstanceId 'INSTANCEID' -confirm:$false 啟用-PnpDevice -InstanceId'INSTANCID' $false } Else { Enable-PnpDevice -InstanceId 'INSTANCEID' -confirm:$false }
預設音訊設備輸出耳機 GAME Set-AudioDevice -ID "deviceid"
預設音訊設備輸出揚聲器 Set-AudioDevice -ID "deviceid"
坦克。
答案1
我從未在 PowerShell 中嘗試過此操作,但我在 PowerShell 中使用此操作:
nircmd.exe setdefaultsounddevice FrontHeadphones
其中FrontHeadphones
是音訊設備的名稱,您需要NirSoft 的 nircmd為了這。
答案2
嘗試下面的方法,並根據需要進行調整。
所有控制面板對話框在幕後所做的就是更改一些註冊表設定。我想要一個可以讓我從一個設定檔更改為另一個設定檔的腳本。
$r = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$regRoot = "HKCU:\Software\Microsoft\"
$profiles = @{"Netbook" = @("Realtek HD Audio output",
"Realtek HD Audio input");
"Bluetooth" = @("Bluetooth Hands-free Audio",
"Bluetooth Hands-free Audio") }
function Write-Message ( [string]$message )
{
echo $message
# Uncomment this line to show dialog outputs from -set
# $r = [System.Windows.Forms.MessageBox]::Show($message)
}
function Set-Mapping ( [string]$devOut, [string]$devIn )
{
echo "Profile audio:`n in = $devIn`n out = $devOut"
$regKey = $regRoot + "\Multimedia\Sound Mapper\"
Set-ItemProperty $regKey -name Playback -value $devOut
Set-ItemProperty $regKey -name Record -value $devIn
}
function List-Devices
{
$regKey = $regRoot + "\Windows\CurrentVersion\Applets\Volume Control\"
echo "Sound devices:"
ls $regKey | where { ! $_.Name.EndsWith("Options") } |
Foreach-Object {
echo (" " + $_.Name.Substring($_.Name.LastIndexOf("\")+1))
}
}
$cmd = $args[0]
switch ($cmd)
{
"-profiles"
{
echo "Sound profiles:"
echo $profiles
}
"-devices"
{
List-Devices
}
"-set"
{
$p = $args[1]
if (!$profiles.ContainsKey($p)) {
echo "No such profile: $p"
echo $profiles
exit
}
Set-Mapping $profiles.Get_Item($p)[0] $profiles.Get_Item($p)[1]
Write-Message "Profile set to: $p"
}
default
{
Write-Message "No such option: $cmd"
}
}
正如你所看到的,它有三個選項:
-profiles – 列出可用的聲音設定檔。
-devices – 列出聲音裝置。
-set [profile] – 設定音訊設定檔。