VMware Horizon Community
MiMenl
Enthusiast
Enthusiast

The “not so“ nice things about sound and Horizon in a healthcare environment.

Ok as the tile suggest I would like to elaborate a bit about sound issues within a horizon environment within a healthcare setting.

But first things first, this might be a different type of post than the usual ones, I might make some strange and wrong assumptions, be bold  at some times but i still think the story might be interesting and might even help solving some issues for others.

Since English is not my native language please bear with me.

Also feel free to correct wrong assumptions and let's try together to make this post as helpful as it can possibly be.

And since this is my first post let me introduce myself a bit :

Mark Platte

36 years old and currently working as an IT architect in a hospital environment.

But my roots are in application development.

I like to solve issues and still believe that when it comes to IT everything can be fixed depending on how much effort and endurance (and too bad also money) you are willing to spend on solving issues. Although determination might actually be the real key word here.

So enough about me so here we go :

It might be i'm not able to finish all of the post so it may come in a couple of posts.

It's not code it's spaghetti, and who doesn't like pasta ?
Tags (3)
12 Replies
MiMenl
Enthusiast
Enthusiast

So here we go Part 1

The post will be setup in the following way.

  • Intro into the environment.
  • Background story .
  • Problem descriptions.
  • Fixes implemented.
  • Conclusion.

Intro into the environment

Since last year we are running a large VDI project within a hospital and we chose VMware Horizon as our main VDI solution, next to Horizon we use DEM for personalization and saving user settings and currently run Window 10 VDI’s. we use Instant clones to provide VDI’s to end users and try to use application virtualization as much as possible. Aslo Tap And go was one of the key points to switch to VDI

During the project we had some nice let’s call it challenges and one of the challenges mainly focused around sound, and I mean SOUND in every aspect.

Background story

This is just a  description (sum up) about the things we encountered here everything looks like it came in at once but in reality things emerged during the project. As always fixing something on the left might always break something at the right.

So there were where after some hard work finally able to roll out VDI’s to the business everything seemed cool, the tests were successful and we had full confidence we build something nice.

But after a short while the first issues started popping up (this article will only focus on sound issues though).

One of the first issues that we heard of was the fact that sound was inconsistent. Some employees had loud sounds other employees could not get the sound loud enough and the last group didn’t get sound all. The irony here is actually quite fun once you fix the issues.

So once we fixed this we ran into something else the sound was always to loud, well just reset it or change it after log on this worked but settings didn’t get saved (many things about this already on the internet). So we went for the log on log of task approach, this seemed to work fine for a while, at least for the people that worked all day at the same desktop from which they never disconnected to their VDI. This was basically the type of user that we started rolling out VDI’s too at start. But then we started rolling out VDI’s to nurses , and if you can say one thing here is that they don’t stay at one spot for a long time. They switch clients a lot since the VDI moves with them. The nursing PC’s are all turned to Kiosk PC’s and there the new issue came up. On every reconnect to the VDI session the sound level was increased to 100%. This might not really look like a big issue and during the day it didn’t matter that much but imagine the following scenario.

You are sleeping as a patient the nurse comes to check on you. But since it’s the night shift in which they also spend a lot of time waiting the nurse decided to watch a nice action movie on Netflix. She turned her sound to 20 % so no one can hear it before she started doing her checkups. She swipes out (tap and go / disconnect her session oh and leaves Netflix running just before that action scene were a bomb explodes) She than takes a mobile card moves it to the patients room, swipes her card connects to her session, sounds are raised to 100 % Netflix still playing bomb explodes and all patients are awake. Not really the wakeup call you would like. So this needs to be fixed (I hear you think but NO blocking Netflix is not an option).

And then  for the final part of the story corona happened, nothing too big since the VDI’s can be used from home too so this was quite easy except for the part were video conferencing became hot. So there come the microphones and webcams, and the issues of the microphone not being loud enough and still some devices not playing sound on the wanted levels.

So see here the challenge we had to face, and even the answers on some things that they could not be fixed (which for now doesn’t seem true) but depends on policies since the solution will involve some programming and making use of third party tools some of them were already mentioned in prior posts but I will name them again.

Below I will try to list the different issues in a more point like manner.

Problem descriptions pointed :

  • High/low sound volume, no sound at all.
  • Microphone not boosted.
  • 100% sound level reset at reconnect.

Fixes Implemented:

General notice : a lot of my solutions are programmed in VB.net I just like it and it saves me time compared to finding my way around in PowerShell. I do think the solutions can also be achieved in PowerShell but this is something you need to do yourself, at least the VB code might give you some general ideas about how to script it.

I will add the source code to the projects were possible so it can be changed and compiled, the community edition of VB.net should be sufficient. I can also provide the compiled binaries but I rather not due to the fact they are .exe files and that always is tricky. (and I didn’t fully read the rules so it might not even be allowed)

 

High/low sound volume, no sound at all.

Trouble shooting this issue was actually quite easy, apparently horizon takes over settings  from the base system when it comes to sound, making the VDI sound relative to current level of the sound volume settings of the client PC

  1. Ex. You put your base system om 50 % in this case sound in the VDI at 100 % is still 50 % of the systems possible volume. Same goes for muting muting your base system will not give you sound trough VDI. And since we run kiosk pc’s users cannot change this themselves. So this needed to be changed by IT.

Our approach.

Since we needed to change a lot of systems it needed to be done in a scripted way. We run W10 as base OS and sound is not easily managed programmatically due to the fact settings are stored in driver classes and not in registry luckily there is a nice tool from NirSoft called SoundVolumeView.( https://www.nirsoft.net/utils/sound_volume_view.html) this tool allows you to set the volume of different devices.

Even though the tool can do a lot for you it would still ask a lot of manual work at least in our environment. We are using a lot of different hardware and drivers so the sound device might be called different on different machines, it is not always clear were sound devices are connected (back port / front port) so lots of options to tackle.

The tool however also has a nice option /scomma <Filename> which lets you export all the devices on a machine to a csv file, this file can then be used to set all the devices to a certain level 100 % in our case. The tool however does not have an option to do this by itself so here we need to create a custom application/ script.

Module Module1

    Sub Main()

        'declare variables and prepare some things for later use.

        Dim strsourcepath As String = "\\test-path\\"

        Dim strAppname As String = "SoundVolumeView.exe"

        Dim strIstFolder As String = ""

        Dim strSolFolder As String = ""

        Dim strCompname As String = My.Computer.Name

        Dim commandlimeargs As String() = Nothing

        Dim strfilename As String = ""

        Dim srFilereader As System.IO.StreamReader = Nothing

        Dim p As New Process()

        Dim pStartInfo As New ProcessStartInfo()

        Dim pset As New Process()

        Dim psetStartInfo As New ProcessStartInfo()

        Dim strLine As String = ""

        Dim strsplit As String() = Nothing

        Dim strDeviceName As String = ""

        Dim bDebug As Boolean = False

        Try

            'create a filename to use for saving the csv file (computername_date_without spaces and 🙂

            strfilename = strCompname & "_Audio_" & Date.Now

            strfilename = Replace(strfilename, " ", "_", 1,, CompareMethod.Text)

            strfilename = Replace(strfilename, ":", "-", 1,, CompareMethod.Text)

            commandlimeargs = Environment.GetCommandLineArgs()

            'check for arguments and take proper action

            For i = 0 To commandlimeargs.Length - 1

                If commandlimeargs(i).ToLower.ToString = "-path" Then

                    strsourcepath = commandlimeargs(i + 1)

                End If

                If commandlimeargs(i).ToLower.ToString = "-debug" Then

                    bDebug = True

                End If

            Next i

            'set folder location for file storage

            strIstFolder = strsourcepath & "\" & "Ist\"

            strSolFolder = strsourcepath & "\" & "Sol\"

            'peroare process to launch SoundVolumeView.exe

            pStartInfo.FileName = strsourcepath & "\" & strAppname

            If bDebug = True Then

                Console.WriteLine("Creating file : " & strIstFolder & strfilename & ".csv")

            End If

            'set parameters for SoundVolumeView.exe to create csv file

            pStartInfo.Arguments = "/scomma " & strIstFolder & strfilename & ".csv"

            'hide SoundVolumeView.exe window

            p.StartInfo.CreateNoWindow = True

            p.StartInfo = pStartInfo

            ' start process

            p.Start()

            p.WaitForExit(60000) ' wait for the process to finish and continue after 60 seconds if process isn't finished

            'prepare cvs file for reading

            srFilereader = New System.IO.StreamReader(strIstFolder & strfilename & ".csv")

            'read cvs file to prefprm actions

            While srFilereader.Peek > -1

                strLine = srFilereader.ReadLine

                strsplit = Split(strLine, ",", , CompareMethod.Text)

                'check for device entries

                If strsplit(1).ToLower.ToString = "device" Then

                    If bDebug = True Then

                        Console.WriteLine("Found device : " & strsplit(0).ToString)

                    End If

                    'prepare process to set volume based on csvfile entries

                    psetStartInfo.FileName = strsourcepath & "\" & strAppname

                    If bDebug = True Then

                        Console.WriteLine("Settig volume to 100 % for device : " & strsplit(0).ToString)

                    End If

                    'set volume of device

                    psetStartInfo.Arguments = "/setvolume " & Chr(34) & strsplit(0).ToString & Chr(34) & " " & "100"

                    pset.StartInfo = psetStartInfo

                    pset.Start()

                    pset.WaitForExit(60000)

                    If bDebug = True Then

                        Console.WriteLine("Unmuting device : " & strsplit(0).ToString)

                    End If

                    'unmute device

                    psetStartInfo.FileName = strsourcepath & "\" & strAppname

                    psetStartInfo.Arguments = "/Unmute " & Chr(34) & strsplit(0).ToString & Chr(34)

                    pset.StartInfo = psetStartInfo

                    pset.Start()

                    pset.WaitForExit(60000)

                    If bDebug = True Then

                        Console.WriteLine("Finished configuring device : " & strsplit(0).ToString)

                    End If

                End If

            End While

            If bDebug = True Then

                Console.WriteLine("Creating file : " & strSolFolder & strfilename & ".csv")

            End If

            'create csv file containing results

            pStartInfo.Arguments = "/scomma " & strSolFolder & strfilename & ".csv"

            p.StartInfo.CreateNoWindow = True

            p.StartInfo = pStartInfo

            p.Start()

            p.WaitForExit(60000)

            Threading.Thread.Sleep(10000)

            srFilereader.Close()

        Catch ex As Exception

            Console.WriteLine("Something went wrong see error description below :")

            Console.WriteLine(ex.ToString)

            Threading.Thread.Sleep(10000)

        End Try

    End Sub

End Module

To create this program start a new console application in vb.net call it SetBaseVolumes and copy the above code to module1.vb

The application has a couple of command line arguments and needs some setup.

-path <path>  the specified path will be used as path to look for the SoundVolumeView.exe file.

-debug will show information in the command prompt else it will just stay black till the process is finished.

Setup:

In the folder that is specified with the path parameter create 2 subfolders :

Sol and Ist.

Your folder setup would look like this :

Path

Path\sol

Path\ist

The folders are used to store the csv file prior to setting values and after so you can check if things changed from a central location.

The application will be compiled to SetBaseVolumes.exe

It is advised to store the executable on a network share and also create a network folder to store the SoundVolumeView.exe also create the ist and sol folder in this directory.

Make sure the program runs under a user with network access we use Altiris with a service account to achieve this, and push a job to all machines.

The syntax could be something like this \\appfolder\setbasevolumes.exe -path \\destfolder\csv

Don’t add the final \ to the destination path this is added by the program.

Working :

The first part of the code is used to declare some variables and prepare some things to launch the processes in a proper way.

Step 1 create a filename based on computer name and time stamp

Step 2 create csv file with all devices for the machine it is run on

Step 3 read csv and set volumes

Step 4 create file with results.

I added some minor comments to the code but feel free to ask questions if needed.

The end result will be that all connect devices on the base (client kiosk pc) will have the volume level set to 100 % and if the device was muted it will be unmuted.

This will only work for connected devices so make sure all the things needed by the end user are plugged in.

So that was part 1 of the solution covering the sound levels of the base machine which seem to be used by horizon as relative sound levels.

Microphone not boosted.

So after we fixed the sound issues of the base system the microphone issue popped up. This also seems related to the base system since VMWare uses the microphone array in the VDI which basically seems to use the local machine settings for the microphone.

We would also like to set this scripted but this device is not listed in the CSV.

Apparently the “Microphone Boost” or “Microfoonversterking” is a virtual device which can be set by SoundVolumeView.exe but with a slightly different command line option.

In this case we used :

soundvolumeview.exe /setvolumedecibel “[device name]” 24

This will set it to the maximum boost.

Keep in mind that depending of the OS language this device name will change in this case

Microfoonversterking = Dutch

Microphone Boost = English

This command should also be run from the pc that needs the setting and the microphone should be plugged in.

Once these setting are done you can manage your sound levels within the VDI by using the master volume and in applications the microphone array settings.

This kind off covered the first two issues from the issue list (for us) so up to the next one.

The sound reset on reconnect. (part 2)

It's not code it's spaghetti, and who doesn't like pasta ?
MiMenl
Enthusiast
Enthusiast

Part 2

100% sound level reset at reconnect.

This was a hard one and actually the one issue that started it all. Trying to find a solution on the internet never got me anywhere.

Lots of recommendations of doing something during log on and log off events but no real solution to the reset of the sound levels to 100 % when reconnecting.

Even asking around at lots of places never got my any further than learn to live with this cannot be fixed.

  1. And that just is an answer I don’t like, and don’t believe (see me introduction  :smileylaugh: )

So yes it was quite some work it involves some 3rth party libraries but in the end I got something that works, only downside due to the way windows manages events it sometimes lags for 1 to 3 seconds before changing the settings but this is always better than not changing them at all.

In this case the user should be able to set the volume themselves so I created a vb.net Form application which resides in the system tray to fix the sound issue.

The application uses xenolightning / AudioSwitcher (https://github.com/xenolightning/AudioSwitcher/blob/master/LICENSE) as wrapper dll to implement some fdunctions to change the sound settings.

These dll’s can be downloaded trough the NuGet function in visual studio :

nuget.png

These DLL’s really made things a lot easier.

And are under a Microsoft Public License

So for the program :

What do we have to fix ?

Well mainly the fact that when you reconnect to a VDI the sound will reset to 100 % and the settings cannot be saved anywhere, since there is no logon or logoff event a logon or logoff DEM script will not fix this either. But it would be nice if the user preferences could be saved and restored trough DEM so let’s keep that in mind.

So what is it I can use to actually know when to change the sound levels, let’s see if there is something triggered when I reconnect back to my VDI. And this seems to be the case. Apparently at least in our environment a reconnect is seen as a session logon or a session unlock two events that can be handled by a VB.net application so let’s try to (ab)use that, and this turned out to become the main part of the program :

Adding an event handler

AddHandler Microsoft.Win32.SystemEvents.SessionSwitch, AddressOf SessionSwitch

And adding a function that triggers

Private Sub SessionSwitch(ByVal sender As Object, ByVal e As Microsoft.Win32.SessionSwitchEventArgs)

If e.Reason = e.Reason = SessionSwitchReason.SessionLogon Or e.Reason = SessionSwitchReason.SessionUnlock Then

Some code to change sound settings and done

End if

End sub

This up here looks easy but after adding some code it just wasn’t working right somehow sound could not be set at once. I read in a post that increasing sound level by 1 and decreasing it again triggers a change with a different NirSoft tool so we had to work from there. And that became the code below.

I added some comments (and if you compile it this way you will have a paypal link to me in the about form but feel free to delete it, although it was quite some work getting this stuff working)

Since the forms contain some element it might be smart to download the source file since it will be easier to recreate.

Setup from scratch :

Add two forms to the project (Form1 and Form 2)

Here is a screenshot of the controls and names on form 1 and form 2

F1.pngF2.png

Add the components to the right forms and take over the right names for the code to work.

Now add the code below to Form1

Form1

'imports some needed libraries dont forget to also reference the dlls into your solution

Imports System.ComponentModel

Imports System.Runtime.InteropServices

Imports AudioSwitcher

Imports Microsoft.Win32

Public Class Form1

    'create a sound device to use

    Public device As AudioSwitcher.AudioApi.CoreAudio.CoreAudioDevice

    Public strappdata As String

    'hide the close button on the form

    Private Const CP_NOCLOSE_BUTTON As Integer = &H200

    Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams

        'make the close button dissapear

        Get

            Dim myCp As CreateParams = MyBase.CreateParams

            myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON

            Return myCp

        End Get

    End Property

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'add an event handler to catch the logon and unlock events

        AddHandler Microsoft.Win32.SystemEvents.SessionSwitch, AddressOf SessionSwitch

        'get the appdata folder for teh user

        strappdata = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

        'get the default playback device usually the master volume when no other devices are present

        device = New AudioApi.CoreAudio.CoreAudioController().DefaultPlaybackDevice

        'print info on a label on the form and resize properly

        Label1.Text = "Current volume level of: " & device.FullName.ToString

        lblvolume.Left = Label1.Left + Label1.Width + 10

        HScrollBar1.Left = lblvolume.Left + lblvolume.Width + 10

        btnmute.Left = HScrollBar1.Left

        Button1.Left = btnmute.Left + btnmute.Width - Button1.Width

        Me.Width = HScrollBar1.Left + HScrollBar1.Width + 25

        'check for setting file and if its present read values from it to set the master volume

        If System.IO.File.Exists(strappdata.ToString & "\SetVolume\Volume.ini") = True Then

            Dim sReader As System.IO.StreamReader = Nothing

            Dim strRead() As String = Nothing

            sReader = New IO.StreamReader(strappdata.ToString & "\SetVolume\Volume.ini")

            While sReader.Peek <> -1

                strRead = Split(sReader.ReadLine, "=")

                If strRead(0).ToString = "Volume" Then

                    'set volume

                    device.Volume = Val(strRead(1).ToString)

                End If

                If strRead(0).ToString = "Mute" Then

                    'set mute state

                    If strRead(1).ToString.ToUpper = "FALSE" Then

                        device.Mute(False)

                    End If

                    If strRead(1).ToString.ToUpper = "TRUE" Then

                        device.Mute(True)

                    End If

                End If

            End While

            sReader.Close()

        Else

            'create the appdata folder if tit is not there to save ini file and store current volume settings

            If System.IO.Directory.Exists(strappdata.ToString & "\SetVolume") = False Then

                System.IO.Directory.CreateDirectory(strappdata.ToString & "\SetVolume")

                System.IO.File.Create(strappdata.ToString & "\SetVolume\Volume.ini").Close()

                Dim sWriter As System.IO.StreamWriter = Nothing

                sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

                sWriter.WriteLine("Volume=" & device.Volume.ToString)

                sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

                sWriter.Close()

            Else

                'store settings in ini file

                System.IO.File.Create(strappdata.ToString & "\SetVolume\Volume.ini").Close()

                Dim sWriter As System.IO.StreamWriter = Nothing

                sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

                sWriter.WriteLine("Volume=" & device.Volume.ToString)

                sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

                sWriter.Close()

            End If

        End If

        'set lebels on primary form

        'change value of scrollbar to show current volume level

        lblvolume.Text = device.Volume & " %"

        HScrollBar1.Value = device.Volume

        If device.IsMuted = True Then

            lblmute.Text = "Muted"

            btnmute.Text = "Unmute"

        Else

            lblmute.Text = "Unmuted"

            btnmute.Text = "Mute"

        End If

        'set interval of timer to 30 seconds and let it write the ini file every 30 seconds to preserve changes.

        Timer1.Interval = 30000

        Timer1.Enabled = True

    End Sub

    Private Sub SessionSwitch(ByVal sender As Object, ByVal e As Microsoft.Win32.SessionSwitchEventArgs)

        'check for event logon or unlock

        If e.Reason = e.Reason = SessionSwitchReason.SessionLogon Or e.Reason = SessionSwitchReason.SessionUnlock Then

            'diabel timer so settings cannot be written and prevent sound setting mechanism to mess up user settings

            Timer1.Enabled = False

            'set volume to 1 and to 0

            device.Volume = 1

            device.Volume = 0

            For a = 0 To 10

                'make the device go to mute state by reapeating the setting (it needs to be repeated to work)

                'device will always start in mute state to prevent loud noises.

                device.Mute(False)

                device.Mute(True)

                Threading.Thread.Sleep(5)

            Next a

            'start reading user settings

            Dim sReader As System.IO.StreamReader = Nothing

            Dim strRead() As String = Nothing

            sReader = New IO.StreamReader(strappdata.ToString & "\SetVolume\Volume.ini")

            While sReader.Peek <> -1

                strRead = Split(sReader.ReadLine, "=")

                For i = 0 To 25 'repest settings 25 times

                    'check for volume

                    If strRead(0).ToString = "Volume" Then

                        Threading.Thread.Sleep(5)

                        'decrease volume by 1

                        device.Volume = Val(strRead(1).ToString) - 1

                        Threading.Thread.Sleep(5)

                        'set volume to desired level

                        device.Volume = Val(strRead(1).ToString)

                    End If

                    If strRead(0).ToString = "Mute" Then

                        'set mute sate

                        If strRead(1).ToString.ToUpper = "FALSE" Then

                            device.Mute(False)

                        End If

                        If strRead(1).ToString.ToUpper = "TRUE" Then

                            device.Mute(True)

                        End If

                    End If

                Next i

            End While

            sReader.Close()

        End If

        'enable timer to save user changes

        Timer1.Enabled = True

    End Sub

    Protected Overrides Sub Finalize()

        MyBase.Finalize()

    End Sub

    Private Sub btnmute_Click(sender As Object, e As EventArgs) Handles btnmute.Click

        'add mute button actions i know GOTO but it's so easy could have used a case instead.

        If device.IsMuted = False Then

            device.Mute(True)

            lblmute.Text = "Muted"

            btnmute.Text = "Unmute"

            GoTo 1

        End If

        If device.IsMuted = True Then

            device.Mute(False)

            lblmute.Text = "Unmuted"

            btnmute.Text = "Mute"

            GoTo 1

        End If

1:

        'write new state to ini

        Dim sWriter As System.IO.StreamWriter = Nothing

        sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

        sWriter.WriteLine("Volume=" & device.Volume.ToString)

        sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

        sWriter.Close()

    End Sub

    Private Sub HScrollBar1_ValueChanged(sender As Object, e As EventArgs) Handles HScrollBar1.ValueChanged

        'handle scrollbar and settings saving

        Try

            Dim sWriter As System.IO.StreamWriter = Nothing

            sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

            device.Volume = HScrollBar1.Value

            lblvolume.Text = device.Volume & " %"

            sWriter.WriteLine("Volume=" & device.Volume.ToString)

            sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

            If device.IsMuted = True Then

                lblmute.Text = "Muted"

                btnmute.Text = "Unmute"

            Else

                lblmute.Text = "Unmuted"

                btnmute.Text = "Mute"

            End If

            sWriter.Close()

        Catch

        End Try

    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick

        'set low interval so when the form becomes visible it will also show the changes made trough the windows sound control

        Timer1.Interval = 300

        Timer1.Enabled = True

        Me.Show()

        Try

            Me.WindowState = FormWindowState.Normal

            If device.IsMuted = True Then

                lblmute.Text = "Unmuted"

                btnmute.Text = "Mute"

            Else

                lblmute.Text = "Muted"

                btnmute.Text = "Unmute"

            End If

        Catch

        End Try

    End Sub

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click

        'hide the program again

        Me.Hide()

        Me.ShowInTaskbar = False

        Timer1.Interval = 45000

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        'save settings in the background every 45 seconds

        lblvolume.Text = device.Volume & " %"

        HScrollBar1.Value = device.Volume

        If device.IsMuted = True Then

            lblmute.Text = "Muted"

            btnmute.Text = "Unmute"

        Else

            lblmute.Text = "Unmuted"

            btnmute.Text = "Mute"

        End If

        Dim sWriter As System.IO.StreamWriter = Nothing

        sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

        sWriter.WriteLine("Volume=" & device.Volume.ToString)

        sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

        sWriter.Close()

        'make me jump in font of all windows when i am visible (!update this might make you loose focus on other apps comment it out to prevent this by adding ' in front)

        If Me.Visible = True Then Me.Activate()

    End Sub

    Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click

        'handle about menu item

        Form2.ShowDialog()

    End Sub

    Private Sub ExitProgramToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitProgramToolStripMenuItem.Click

        'handle exit menu item

        Me.Close()

    End Sub

    Private Sub Form1_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing

        'save settings befor closing the app

        Try

            Dim sWriter As System.IO.StreamWriter = Nothing

            sWriter = New IO.StreamWriter(strappdata.ToString & "\SetVolume\Volume.ini", False)

            device.Volume = HScrollBar1.Value

            lblvolume.Text = device.Volume & " %"

            sWriter.WriteLine("Volume=" & device.Volume.ToString)

            sWriter.WriteLine("Mute=" & device.IsMuted.ToString)

            If device.IsMuted = True Then

                lblmute.Text = "Muted"

                btnmute.Text = "Unmute"

            Else

                lblmute.Text = "Unmuted"

                btnmute.Text = "Mute"

            End If

            sWriter.Close()

        Catch

        End Try

    End Sub

    Private Sub OpenAppDataToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles OpenAppDataToolStripMenuItem1.Click

        'handle open appdata menu item

        Process.Start("c:\windows\explorer.exe", strappdata.ToString)

    End Sub

    Private Sub AboutToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem1.Click

        Form2.StartPosition = FormStartPosition.CenterScreen

        Form2.ShowDialog()

        Me.Activate()

    End Sub

    Private Sub ShowFormToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ShowFormToolStripMenuItem.Click

        Timer1.Interval = 300

        Timer1.Enabled = True

        Me.Show()

        ' Me.ShowInTaskbar = True

        Me.WindowState = FormWindowState.Normal

        If device.IsMuted = True Then

            lblmute.Text = "Unmuted"

            btnmute.Text = "Mute"

        Else

            lblmute.Text = "Muted"

            btnmute.Text = "Unmute"

        End If

    End Sub

End Class

This is the main program

Add yor own text to the label on form2 currently it is :

Program to store the default audio device volume settings

within a VDI session.

The program will restore the sound level of the default sound device

on a session reconnect.

Settings are stored in %AppData%\SetVolume\Volume.ini

© Mark Platte 2020

mimenl@gmail.com

I would appreciate it if you would leave this in.

Add the following code to Form2

:smileyinfo: This is the about stuff but since code from Form1 needs it I added it here too

From2

Public Class Form2

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Me.Hide()

    End Sub

    Private Sub lbldonate_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles lbldonate.LinkClicked

        System.Diagnostics.Process.Start(e.Link.LinkData.ToString())

    End Sub

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        lbldonate.Links.Clear()

        Try

            'jkust a check to take out the label when running i a known domain environment

            If Environment.UserDomainName.ToUpper.ToString <> "somedomain" Then

                If Environment.UserDomainName.ToUpper.ToString <> "somedomain1" Then

                    lbldonate.Visible = True

                    Label2.Visible = True

                    lbldonate.Text = "Donate"

                    lbldonate.Links.Add(0, 6, "https://paypal.me/mimenl")

                End If

            End If

        Catch a As Exception

            lbldonate.Visible = True

            Label2.Visible = True

            lbldonate.Text = "Donate"

            lbldonate.Links.Add(0, 6, "https://paypal.me/mimenl")

        End Try

    End Sub

End Class

Taking this out will have some impact on changing the code and the components when you build it from scratch based on the provided code samples.

If you download the source it can be changed quite easy. But I would like / appreciate it if you would keep mentioning me in some way. I just decide  to share since this problem was really bugging me and can be quite an inconvenience for people around you.

Well I hope it will also work for you, running in debug mode from Visual studio might not always work. Compiling and running the compiled exe seems to work better.

There is not much error handling and I could only test it in our environment so let me know if things don’t work out so I can see if I can fix it.

The user settings are stored in the roaming appdata folder and can easily be saved using DEM.

Basically the flow of the application is like this  :

Save usersettings -> user disconnects-> user reconnects -> unlock/reconnect event is triggers-> Load usersettings-> restore settings -> volume is on desired level.

As mentioned before the reconnect / unlock event is not always trigger before actual sound is played, which might still cause the sound to be at 100 % for a short while.

Conclusion

Well it seems that something as simple as sound is not so simple after all. I still think that it’s fundamentally wrong that we see the 100 % behavior happening, and still feel it should be fixed in a different way. Maybe by letting the horizon agent interact with the base system and make it able to change sound setting there.

Also it seems that windows 10 itself has some weird behavior too. Try muting your VDI without the program running, while playing something on youtube, now reconnect sound will be at 100% you hear YouTube w10 will still show your device is muted.

The fixes in this post seem to work in our environment but might still not be the best but for now we don’t have much choice.

The fun part is that even when a lot of people stated it couldn’t be done there is still something that does the trick !

Let me know what you think, and if you need any help or want to get a discussion going on sound and horizon I would be happy to join.

In the end I hope that all these things are not necessary and that we are doing something totally wrong and that someone could tell me how to fix it without any self-build tools just by using what’s available in DEM and Horizon.

But is sure was a great learning experience.

Well time to log off again, and in case the code doesn't appeal to you : "It isn't code it's spaghetti Smiley Happy"

It's not code it's spaghetti, and who doesn't like pasta ?
ijdemes
Expert
Expert

Hi Mark,

Ok, wow! What an extensive and detailed post! Great work and thanks for sharing!

I agree that it is best to have this fixed/adjusted in the product. Have you done a feature request for this? --> https://www.vmware.com/company/contact/contactus.html?department=prod_request

Thanks again!


\\ Ivan
---
Twitter: @ivandemes
Blog: https://www.ivandemes.com
pieterheijms
Enthusiast
Enthusiast

Hi Mark,

Wow, what a nice post! Thanks for sharing!

I have a question, I work also in a large hospital in the south, same country as you.

We are going to implement a Horizon environment W10 with DEM and App Volumes (2 or 4), within the next 6 months. At the moment we use Citrix XenDesktop, that will be migrated to Horizon. We use around 2000 concurrent VDI's and a lot of fat clients. At the moment we are designing (together with a third party) our environment. Is it possible to make an appointment with you, so we can come to your hospital and see how your environment is set-up, problems, lessons learned, etc. Let me know if that is possible for you.

Best regards,

Pieter

Reply
0 Kudos
MiMenl
Enthusiast
Enthusiast

Hi Mark,

Ok, wow! What an extensive and detailed post! Great work and thanks for sharing!

I agree that it is best to have this fixed/adjusted in the product. Have you done a feature request for this? --> https://www.vmware.com/company/contact/contactus.html?department=prod_request

Thanks again!

Yeah i could do that Smiley Happy,

I think it's a known issue and that for now there wasn't much of a solution.

I'll take a  look at the page you linked to see I can fill in a feature request, maybe they can also find a way based on event handling from a DEM agent or something. since that service is used a lot in Horizon environments anyway and runs. or maybe even the horizon agent itself.

It's not code it's spaghetti, and who doesn't like pasta ?
Reply
0 Kudos
MiMenl
Enthusiast
Enthusiast

Hi Mark,

Wow, what a nice post! Thanks for sharing!

I have a question, I work also in a large hospital in the south, same country as you.

We are going to implement a Horizon environment W10 with DEM and App Volumes (2 or 4), within the next 6 months. At the moment we use Citrix XenDesktop, that will be migrated to Horizon. We use around 2000 concurrent VDI's and a lot of fat clients. At the moment we are designing (together with a third party) our environment. Is it possible to make an appointment with you, so we can come to your hospital and see how your environment is set-up, problems, lessons learned, etc. Let me know if that is possible for you.

Best regards,

Pieter

I send you PM,

Regards,

Mark

It's not code it's spaghetti, and who doesn't like pasta ?
Reply
0 Kudos
DEMdev
VMware Employee
VMware Employee

Hi Mark,

First off, thank you for providing these tools and the extensive write-up. Much appreciated! Maybe also worth posting (a link to) this in the VMware Horizon® forum?

As for filing a feature request, please use https://wsone-horizon.ideas.aha.io/​, as that seems to be the new process for EUC products.

zhi
VMware Employee
VMware Employee

Hi Mark,

  Thanks for the detailed post and great sharing.

  Which Horizon version did you use?

  And I heard that there were some fixes in recent Horizon regarding audio out volume level. Would you please help to take a try with the latest Horizon? thank you in advance.

Reply
0 Kudos
RobinHarmsen
Enthusiast
Enthusiast

Hi zhi,

This is a colleague of Mark, we are currently using Horizon 7.13.1...

We are not ready to transition to 8 yet..., it sounds promising that there are fixes in recent Horizon versions.

Reply
0 Kudos
NickTT
Enthusiast
Enthusiast

I still find issues with audio in 8. The volume and mute keys not doing anything even though windows is shows the volume going up and down. This seems to be tied to the HTLM5 redirected stuff though. Work around is just use the volume controls in sites like YouTube instead.

The bigger issue we are running into is if you use Laptops as your terminal. We have discovered that if you undock a laptop while on Horizon and then dock back up, Teams will no longer work with your audio devices. It will refuse to pickup or connect to meetings till you completely close the Horizon Client and then relaunch it on the laptop. You don't have to restart your VDI machine. This seems to "unstuck" the audio hooks built into the Horizon Client for Teams and lets Teams behave as expected. I REALY miss S4B.... it worked SOOO much better in VDI.

Reply
0 Kudos
MiMenl
Enthusiast
Enthusiast

hi Zhi,

 

A late reply,

in 7.13.1.. is seems that sound works ok, atleast trough client when it comes to store the sound level properly when disconnecting en reconnecting. (no  boost to 100 %) also the mute status is properly handled (it used to unmute)

As Robin mentioned we are not yet at horizon 8. once we are I'll also update this post once we are.

 

 

It's not code it's spaghetti, and who doesn't like pasta ?
Reply
0 Kudos
JamesETaylor
Contributor
Contributor

Just stubbled across this when looking into a very minor audio issue for our small Horizon VDI solution.

Its not related to anything we are seeing but I wanted to add a comment to say that is some very nice work. I love seeing IT experts putting in the extra effort to fix all those little issues that drive users crazy. It really helps instil trust and professionalism in the work we do in IT. It also really helped me appreciate how complex Horizon can get as you scale up to large desktop pools. Something I'll keep in mind as we grow our solution.

Reply
0 Kudos