2017-08-16 118 views
2

我正在尋找一個解決方案,靜音系統的聲音在我的Windows 7 PC,而且我發現很多地方推薦以下VB腳本:爲什麼vb腳本無法在Windows 7 PC上工作?

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

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

所以我救以上行到一個名爲「sound.vbs」的文件,然後雙擊它運行,但聲音仍然是,爲什麼?什麼是正確的做法?

回答

1

你應該運行它這個腳本:

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> 
相關問題