audio - 为什么在Windows 7 PC上无法使用vb脚本使声音静音?

标签 audio vbscript windows-7 mute

我正在寻找一种使Windows 7 PC上的系统声音静音的解决方案,并且我发现很多地方推荐以下vb脚本:

Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(&hAD))

要么
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys(chr(173))

所以我将以上几行保存到一个名为“sound.vbs”的文件中,然后双击运行它,但声音仍然打开,为什么?什么是正确的方法?

最佳答案

您应该将其作为以下脚本运行:

set oShell = CreateObject("wscript.shell")
oShell.SendKeys(" " & chr(173)) 'Allows you to toggle( mute / unmute )

我有一个旧的HTA文件,它在Windows 7上对我有用: Sound.hta
<html>
<head>
<HTA:APPLICATION 
APPLICATIONNAME="Volume + - ON/OFF" 
BORDER="THIN" 
BORDERSTYLE="NORMAL" 
ICON="SndVol.exe" 
INNERBORDER="NO" 
MAXIMIZEBUTTON="NO" 
MINIMIZEBUTTON="NO" 
SCROLL="NO" 
SELECTION="NO" 
SINGLEINSTANCE="YES"/>
<title>Volume + - ON/OFF </title>
<script language="vbscript">
'************************************************************************************
Sub window_onload()
    CenterWindow 250,150
End Sub
'************************************************************************************
Sub Sleep(MSecs)' Fonction pour faire une pause car wscript.sleep ne marche pas dans un HTA 
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
    Dim tempName : tempName = "Sleeper.vbs"
    If Not Fso.FileExists(tempFolder&"\"&tempName) Then
        Set objOutputFile = fso.CreateTextFile(tempFolder&"\"&tempName, True)
        objOutputFile.Write "wscript.sleep WScript.Arguments(0)"
        objOutputFile.Close
    End If
    CreateObject("WScript.Shell").Run tempFolder&"\"&tempName &" "& MSecs,1,True
End Sub
'************************************************************************************
Sub Volume(Param)
    set oShell = CreateObject("WScript.Shell") 
    Select Case Param 
    Case "MAX"
        oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
        Sleep 2000 'Waits For The Program To Open
        oShell.SendKeys("{HOME}")' volume maximum 100%
        Sleep 100
        oShell.SendKeys"%{F4}"  ' ALT + F4
    Case "MIN"
        oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
        Sleep 2000 'Waits For The Program To Open
        oShell.SendKeys("{END}") 'volume minimum 0% 
        Sleep 1000
        oShell.SendKeys"%{F4}"  ' ALT + F4
    Case "UP"
        oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
        Sleep 2000 'Waits For The Program To Open
        oShell.SendKeys("{PGUP}") 'volume +20%
        Sleep 1000
        oShell.SendKeys"%{F4}"  ' ALT + F4
    Case "DOWN"
        oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
        Sleep 2000 'Waits For The Program To Open
        oShell.SendKeys("{PGDN}") 'Turns Up The Volume 20, If It Is Muted Then It Will Unmute It
        Sleep 1000
        oShell.SendKeys"%{F4}"  ' ALT + F4
    Case "MUTE"
        oShell.run "%SystemRoot%\System32\SndVol.exe" 'Runs The Master Volume App.
        Sleep 1000 'Waits For The Program To Open
        oShell.SendKeys(" " & chr(173)) 'permet de couper/remettre le son (bascule)
        Sleep 1000
        oShell.SendKeys"%{F4}"  ' ALT + F4
    End select
End Sub
'*************************************************************************************
Sub CenterWindow(x,y)
    Dim iLeft,itop
    window.resizeTo x,y
    iLeft = window.screen.availWidth/2 - x/2
    itop = window.screen.availHeight/2 - y/2
    window.moveTo ileft,itop
End Sub
'************************************************************************************
</script>
</head>
<body>
<center>
<BUTTON style="background: Red; color: white;" onClick="Call Volume('MAX')" style="WIDTH: 85px; HEIGHT: 30px">Volume MAX</BUTTON>&nbsp;&nbsp;
<BUTTON style="background: Blue; color: white;" onClick="Call Volume('MIN')" style="WIDTH: 85px; HEIGHT: 30px">Volume MIN</BUTTON>&nbsp;&nbsp;
<BUTTON style="background: Green; color: white;" onClick="Call Volume('UP')" style="WIDTH: 85px; HEIGHT: 30px">Volume +20%</BUTTON>&nbsp;&nbsp;
<BUTTON style="background: Orange; color: white;" onClick="Call Volume('DOWN')" style="WIDTH: 85px; HEIGHT: 30px">Volume -20%</BUTTON>&nbsp;&nbsp;
<BUTTON style="background: DarkOrange; color: white;" onClick="Call Volume('MUTE')" style="WIDTH: 85px; HEIGHT: 30px">ON/OFF</BUTTON>&nbsp;&nbsp;
</center>
</body>
</html>

关于audio - 为什么在Windows 7 PC上无法使用vb脚本使声音静音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45723291/

相关文章:

android - 获取默认的声音目录

javascript - HTML 音频录制到静音?

asp-classic - ASP - 如何从用户输入文本中删除单引号

WPF 菜单未正常定位

java - Launch4j - java 可执行包装器 - Windows7

javascript - jPlayer-用海报播放一系列mp3文件

javascript - HTML5 音频没有使用我的 JS 脚本暂停?

c# - 在 ASP、C# 和 VB.Net 中如何检索当前行号

excel - 在存储在另一个文件中的 CSV 文件上运行宏

c# - 是否可以调用 win form 而不是 windows 登录窗口?