Tuesday, November 18, 2008 Login
VinsVision
Articles
 Search articles Minimize
  
 Article archive Minimize
  
 Article list Minimize
Windows Installer .msi
Policies
Deployment


  
 Setting The Sound Volume Level Using a Scriptable ActiveX Control Minimize
Location: BlogsVinsVision's articlesPolicies    
Posted by: Vincent Wednesday, June 06, 2007
Hearing Windows startup and other sounds from Windows events is just fine, but it can get quite annoying if someone has set their computers’ sound volume at a 100%. This is especially true at big offices or classrooms with many people and computers. Because turning off the soundcard in computers in not always an option, this article will explain how you can control the volume level on computers with programmatically using a vbscript and an ActiveX object. Included are the ActiveX file, a sample vbscript and a Windows Installer msi file for deployment purposes.

Set The Sound Level

To set the volume level of the microphone and volume levels we will use an ActiveX object loosly based on a Microsoft sample download. Using a vbscript logonscript you’re able to manipulate the volume level programmatically.

Get Started

Setting the soundlevel is easy. From the download section, download the SetSoundLevel zip file. This file contains the SetSoundLevel ActiveX file, a sample vbscript and a Windows Installer msi package for installing the control using group policy or System Management Server.

Manual Installation

First you have to download the SetSoundLevel zip file. To perform a manual installation, copy the SetSoundLevel.dll control to your computer. To the %ProgramFiles%\SetSoundLevel folder for example. Then run the following command:

Regsvr32 “%ProgramFiles%\SetSoundLevel\SetSoundLevel.dll”

 Regsvr32.exe ActiveX Control SetSoundLevel.jpg

The regsvr32.exe command should return a message saying the installation succeeded.

Automatic Installation

The Windows installer file, SetSoundLevel.msi, is included in the download and does the same thing.

Set Sound Level Windows Installer Installation.jpg

Open it and click Next, Next, Finish and you’re done.

Note: You have to be local administrator to do perform these actions.

Automatic installation can be achieved by using System Management Server or Intellimirror group policy and assign it to the Computer Configuration --> Software Installation (Publishing the .msi to users will not work).

Testing

After the control is installed on your machine, you can use the included vbscript, setsoundlevel.vbs, to test setting the sound volume level.

Sub SetSoundLevel ( iMyLevel )

On Error Resume Next
Err.Clear

Dim blSoundDevicePresent
Dim objSoundDevice

blSoundDevicePresent = False

For Each objSoundDevice In GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("Win32_SoundDevice")
 blSoundDevicePresent = True
 Exit For
Next

If Not blSoundDevicePresent Then Exit Sub

Dim iDefaultLevel, iSoundLevel, objSoundLevel

iDefaultLevel = 5

If Not IsNumeric ( iMyLevel ) Then iMyLevel = iDefaultLevel

MyLevel = CInt ( iMyLevel )
If Err.number <> 0 Then iMyLevel = iDefaultLevel

If iMyLevel < 0 Or iMyLevel > 100 Then iMyLevel = iDefaultLevel

Err.Clear
set objSoundLevel = CreateObject ( "SetSoundLevel.SoundLevel" )
If Err.number <> 0 Then Exit Sub

iSoundLevel = iMyLevel * ( objSoundLevel.GetMaxSoundLevel - objSoundLevel.GetMinSoundLevel ) / 100

objSoundLevel.SetSoundLevel iSoundLevel

set objSoundLevel = Nothing

End Sub

Note: For security reasons, the script is named setsoundlevel.vbs.txt. Remove the .txt extension before you try to run this script.

If you open the script, you will find a subroutine named SetSoundLevel. It will take an integer value between 0 and 100 to set the sound volume level. By default the script will set the level to 10(%).

You can easily incorporate this subroutine in your existing logon vbscript or run it as a separate logon script.

Note: Just be sure you remove the msgbox "Finished" statement from the script

More Information:

178456 SAMPLE: Volume.exe: Set Volume Control Levels Using Visual Basic (Volume.exe)

Let me know how it worked out for you and add a comment!

Permalink |  Trackback

Comments (3)   Add Comment
Re: Setting The Sound Volume Level Using a Scriptable ActiveX Control    By Mark on Thursday, August 09, 2007
This worked nicely in XP and is useful as a scheduled task running every hour or so.

I tried this in a Windows Server 2003 Terminal Server in Application Mode, however it seemed to have no effect within a client session. Would you be interested in posting a version that works in a terminal session?

Re: Setting The Sound Volume Level Using a Scriptable ActiveX Control    By Scott on Saturday, September 29, 2007
Works great with XP, after finding a typo and a bug in the code.
It will always set the default level of 5 unless you change:

MyLevel = CInt ( iMyLevel )
If Err.number <> 0 Then iMyLevel = iDefaultLevel

To read:

err.Clear
iMyLevel = CInt ( iMyLevel )
If Err.number <> 0 Then iMyLevel = iDefaultLevel

Nice work otherwise...and thanks!

Re: Setting The Sound Volume Level Using a Scriptable ActiveX Control    By James on Monday, March 24, 2008
It says 'microphone and sound level' volumes, however, I can't change the microphone volume. That's what I was really hoping for.


Your name:
Title:
Comment:
Add Comment   Cancel 
  
Copyright 2007 by VinsVision  | Terms Of Use | Privacy Statement