Search code examples
vb.netvolume

Control Volume in vb.net


I need to control the main computer volume in vb.net. I have searched the web and tried all the examples I could find. None of the have worked.

Does anyone have some snippets of code that work with vb.net 2010 to control volume?

Thanks
giodamelio


Solution

  • I found an answer. Its uses Nirsoft's NirCmd (32-bit , 64-bit)

    Public Class Sound
        Dim nircmd As String
        Const MAXVOL As Integer = 65535
    
        Public Sub New(ByVal nircmd_location As String)
            nircmd = nircmd_location
        End Sub
    
        Public Sub setVol(ByVal level As Integer)
    
            Dim p As New ProcessStartInfo
            p.FileName = nircmd
            p.Arguments = "setsysvolume " & (MAXVOL * (level / 100)).ToString
            Process.Start(p)
    
        End Sub
    End Class
    

    You can then use somthing like

    Dim vol As New Sound(path_to_nircmd)
    vol.setVol(50)