gpt4 book ai didi

audio - 使用VBScript切换当前的有源声音设备?

转载 作者:行者123 更新时间:2023-12-03 02:13:51 27 4
gpt4 key购买 nike

我想在连接到计算机(Windows 7 32位)的两个音频设备之间切换。我看了一下question,发现了nircmd

现在,我可以创建两个VBS文件以在两个设备之间切换。我想知道是否可以找到当前的 Activity /默认声音设备,然后将所有内容都放在一个文件中。

我当前的代码是-

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("L:\MyApps\NirCmd\nircmd.exe setdefaultsounddevice ""Speakers""", 0, True)
Set WshShell = Nothing

另一个文件具有“耳机”而不是“扬声器”。

最佳答案

这就是我目前解决的方式。我知道,这很糟糕。它找不到当前 Activity 的设备,而是将信息存储在文本文件中(该文件必须已经存在!其中包含当前设备名称!)。是的,这太可怕了。但是考虑到我对VBScript的了解和对Windows Registry的当前了解,两者都几乎为零,这是我能想到的最好的!

我将其发布在这里,因为在其他任何地方都缺少简单的答案。如果有人在不使用任何其他程序的情况下有更好的解决方案,我将不胜感激。

另外,如果有人想使用此代码,请更改文件路径和名称以适合您的文件路径和名称。

Dim objFso, objFileHandle, strDisplayString
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
Set readObjFileHandle = objFso.OpenTextFile("L:\MyApps\NirCmd\CurrentDevice.txt", 1)

strDisplayString = readObjFileHandle.ReadLine()
readObjFileHandle.Close

Set writeObjFileHandle = objFso.OpenTextFile("L:\MyApps\NirCmd\CurrentDevice.txt", 2, "True")

If StrComp(strDisplayString, "Headphones", vbTextCompare) = 0 Then
'MsgBox "Headphones - switching to Speakers"

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("L:\MyApps\NirCmd\nircmd.exe setdefaultsounddevice ""Speakers""", 2, True)
Set WshShell = Nothing

writeObjFileHandle.Write("Speakers")
Else
'MsgBox "Speakers - switching to Headphones"

Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("L:\MyApps\NirCmd\nircmd.exe setdefaultsounddevice ""Headphones""", 2, True)
Set WshShell = Nothing

writeObjFileHandle.Write("Headphones")
End If

writeObjFileHandle.Close

关于audio - 使用VBScript切换当前的有源声音设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21800476/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com