Volume Control Snapshot

Hello gurus, first my acknowledgements to the people who made this possible:

This service is for people who share their computer between two or more Windows users. Usually, every person log, in and adjusts the volume level to his (her) preferences. When another user logs in, he (she) notices that the volume levels are not the same as when he (she) logged off. This can be annoying (like for me), so I decided to write this service to store the volume levels in the Registry every time a user logs off and then restore them back when the same user logs in.

As a requirement, you need to enable the sucess of auditing logon events at Local Security Settings. This allows that the system can issue the security events that you need to back up or restore volume levels.

When the service starts, it first creates an EventLog object and lets it fire events. It also instanciates a Mixer object to get/set the volume levels (thanks, Tom Archer):

protected override void OnStart(string[] args) {
   EL = new EventLog();
   EL.Log = "Security";

   EL.EnableRaisingEvents = true;
   EL.EntryWritten += new EntryWrittenEventHandler(EL_EntryWritten);

   mMixers = new Mixers();
}

When the service captures an event, it checks whether the category is Logon/Logoff and that the user logging on or off is from the current machine:

if (e.Entry.CategoryNumber == 2 &&  e.Entry.UserName.Substring(0,
   e.Entry.UserName.IndexOf(@"\"))  == e.Entry.MachineName) {

All the Registry keys that the service writes/reads are specified by:

RegistryKey Key =
   Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Volume Control
   Snapshot", RegistryKeyPermissionCheck.ReadWriteSubTree);

Then, it looks into e.Entry.InstanceId to know whether this is a LogOn or LogOff event.

In case of a LogOff event, it needs to store the levels at the Registry and cicles among all the controls of the playback and recording controls, creating at each iteration a value in the Registry.

foreach (MixerLine Line in mMixers.Playback.Lines) {

foreach (MixerLine Line in mMixers.Recording.Lines) {

When the user is LoggingOn it's similar. The difference is that now it reads the Registry and sets the volume levels.

It's importat to say that not every setting at volume control is recorded—only the volume level, mute checkbox, and selected checkbox. The class provided by CastorTiu is powerful and allow you to get/set every control, but it works perfectly for me that way. Feel free to enhance the service.

If the service catches an exception, it writes the content into a text file (C:\Errors.txt).

You can download the solution to compile and/or modify the code, or you can download the binary to put it work immediatly. Of course, it needs the .NET Framework 2.0. To create the service, you need to use INSTALLUTIL that executes the installer at the assembly.

Thats all. I hope this can be helpful to you. Fidencio Monroy.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: May 18, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT While the idea of using facial and/or gesture recognition to create a modern, intuitive game seems attractive, some developers may want to leverage Unity 3D as a way to accelerate their development efforts. There are many different ways in which Intel and Unity Technologies have been working together to help speed the development of games with the Intel® RealSense™ SDK (software developer kit). Check out this upcoming eSeminar to join a …

  • Cloud archive solutions come of age as a practical, profitable alternative. Tape has become a mainstay of corporate IT. Yet, tape is fallible and many organizations have at one point or another experienced the downfall of using tape for corporate data archiving. While redundancy and other solutions are available to increase the reliability and security of tape, the problem remains that tape is a physical media.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date