如何使用脚本更改Win7主音量?
我想要一个适用于 Windows 7 的脚本,这样我可以输入“vol 50”,音量就会更改为 50%,输入“vol 0”,它就会静音,等等。
这应该很简单吧?
显然,事实并非如此,我已经浪费了一个多小时费力地阅读各种无聊事物的冗长解释,人们在解释 Win 7 和 Win XP 之间或主卷和其他卷之间的差异,以及其他各种没有告诉我的事情我需要什么。
我找到了此页面: http://msdn.microsoft.com/en-us/library/ms679141.aspx
所以我尝试创建一个测试 set_vol_50.vbs 脚本,如下所示:
SetMasterVolume 0.5 , NULL
这会导致错误:
Script: <path>\set_vol_50.vbs
Line: 1
Char: 1
Error: Type mismatch: 'SetMasterVolume'
Code: 800A000D
Source: Microsoft VBScript runtime error
这不是特别有帮助(也没有尝试谷歌搜索)。
我需要以某种方式将 0.5 转换为浮点数吗?
第二个参数使用 NULL 是否错误?
我并没有为此而与 vbscript 结婚 - 我想做的只是全局设置 Windows 7 的主音频音量 - 一旦最终结果是一个可以接受百分比的简单可执行文件,我就会很高兴。
我该怎么做?
I want a script for Windows 7 so I can type "vol 50" and the volume gets changed to 50%, "vol 0" and it mutes, and so on.
This should be really simple, right?
Apparently, it's not, and I've wasted over an hour wading through various long explanations of boring things where people are explaining differences between Win 7 and Win XP or between master volume and other volumes, and various other things that aren't telling me what I need.
I found this page: http://msdn.microsoft.com/en-us/library/ms679141.aspx
So I tried creating a test set_vol_50.vbs script that looks like this:
SetMasterVolume 0.5 , NULL
This results in the error:
Script: <path>\set_vol_50.vbs
Line: 1
Char: 1
Error: Type mismatch: 'SetMasterVolume'
Code: 800A000D
Source: Microsoft VBScript runtime error
Which isn't particularly helpful (and neither is trying to google on that).
Do I need to cast 0.5 to a float somehow?
Is NULL the wrong thing to use for the second argument?
I'm not married to vbscript for this - all I want to do is globally set the master audio volume for Windows 7 - once the end result is a simple executable that can accept a percentage, I'll be happy.
How do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有人向我推荐了这个免费软件工具: http://www.nirsoft.net/utils/nircmd.html
这最终允许我创建一个像这样的批处理文件:
这解决了问题,但有点难看。
如果有人可以提供更好的解决方案,我会很乐意接受它,但至少我有一些可行的东西。
Someone pointed me towards this freeware tool: http://www.nirsoft.net/utils/nircmd.html
Which ultimately allows me to create a batch file like this:
Which solves the problem, but is a bit ugly.
If someone can provide a better solution, I'll happily accept it over this, but at least I've got something which works.