开关使用VBScript当前活动的声音设备? [英] Switching current active sound device using VBScript?

查看:114
本文介绍了开关使用VBScript当前活动的声音设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到我的电脑两个音频设备(Windows 7的32位)之间切换。我看了一下问题和发现的的NirCmd

I want to switch between two audio devices connected to my computer (Windows 7 32 bit). I had a look at question, and found nircmd.

现在,我能够创建两个VBS文件来在两个设备之间进行切换。我在想,如果我能找出当前的活动/默认声音设备是什么,然后我可以把一切都放在一个文件本身。

Now, I'm able to create two VBS files to switch between the two devices. I was wondering if I could find out what the current active/default sound device is, then I could put everything in one file itself.

我目前的code是 -

My current code is -

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

其他的文件有耳机,而不是扬声器。

The other file has "Headphones" instead of "Speakers".

推荐答案

这是我如何解决它目前。这吸大的时候,我知道了。它没有找到当前活动设备,而不是存储在文本文件中的信息(其具有对已经存在!随着它当前设备名称!)。是的,这太可怕了。但考虑到我的VBScript的知识和Windows注册表,这两者都是非常接近零的现有知识,这是我能想出!最好

This is how I solved it currently. This sucks big time, I know. It doesn't find the current active device, instead stores the information in a text file (which has to already exist! With the current device name in it!). Yes, it's horrible. But considering my knowledge of VBScript and current knowledge of the Windows Registry, both of which are very near zero, this is the best I could come up with!

我在这里张贴这一点,因为缺乏一个简单的答案其他地方的。如果任何人有任何更好的解决方案,而无需使用任何其他程序,我会很感激知道了。

I'm posting this here, because of a lack of a simple answer anywhere else. If anybody has any better solutions, without using any other programs, I'll be very grateful to know.

另外,如果有人想用这个code,请更改文件路径和名称,以适合你的。

Also, if anybody wants to use this code, please change the file paths and names to suit yours.

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

这篇关于开关使用VBScript当前活动的声音设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆