Jump to content

Microphone sound enable / disable


Seminko
 Share

Go to solution Solved by Danyfirex,

Recommended Posts

  • 3 months later...

How does it decide which mic to mute? cause it mutes my 4th mic instead of the default mic

[Edit] actually it mutes every mic except for the default mic. 3 out of 4 microphones muted, the unmuted one being the default.

[Edit2] doesn't matter which is the default, it just doesn't work with that particular mic.

Edited by Carlo84
Link to comment
Share on other sites

How does it decide which mic to mute? cause it mutes my 4th mic instead of the default mic

[Edit] actually it mutes every mic except for the default mic. 3 out of 4 microphones muted, the unmuted one being the default.

[Edit2] doesn't matter which is the default, it just doesn't work with that particular mic.

I will look later how to.

Saludos

Link to comment
Share on other sites

2 devices that don't work are the Logitech G930 headset and the Logitech C920 webcam with build in mic.

Both are USB devices perhaps that is the reason they do not work.

$iDeviceCount does recognizes them but the actions after that do not apply

Edited by Carlo84
Link to comment
Share on other sites

right now I don't have time to program but you can see here. maybe that helps you.

Saludos

Link to comment
Share on other sites

  • 3 years later...

Hi Mr @Danyfirex !

It's been a long time, almost four years, wow.

Anyways, I now switched to W10 and your awesome script stopped working for me. It now says 'Not incoming Parts in Part'.

The only thing that made sense to me is change this line:

If StringInStr($sPartName, "mic") Then

to this, since the name changed from Microphone to Rear Pink In:

If StringInStr($sPartName, "Pink") Then

 

image.png.70cf09dcd3a3420a7c9114c36d460de0.png

 

Here's the console log:

>>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<
+Part
>Realtek HD Audio output ID: 65537
+Part
>Celkové ztlumení ID: 131073
+Part
>Reproduktory ID: 131072
+Part
>Sum ID: 131074
+Part
> ID: 65536
Not incoming Parts in Part
+Part
>Ztlumit ID: 131075
+Part
>Rear Black In ID: 131076
+Part
>Rear Black In ID: 65538
Not incoming Parts in Part
+Part
>Ztlumit ID: 131077
+Part
>Rear Orange In ID: 131078
+Part
>Rear Orange In ID: 65539
Not incoming Parts in Part
+Part
>Ztlumit ID: 131079
+Part
>Rear Pink In ID: 131080
+Part
>Rear Pink In ID: 65540
Not incoming Parts in Part
+Part
>Ztlumit ID: 131081
+Part
>Front Pink In ID: 131082
+Part
>Front Pink In ID: 65541
Not incoming Parts in Part
+Part
>Ztlumit ID: 131083
+Part
>Rear Blue In ID: 131084
+Part
>Rear Blue In ID: 65542
Not incoming Parts in Part
+Part
>Ztlumit ID: 131085
+Part
>Front Green In ID: 131086
+Part
>Front Green In ID: 65543
Not incoming Parts in Part
+Part
>Side ID: 131087
+Part
>Side ID: 65544
Not incoming Parts in Part
+Part
>Center ID: 131088
+Part
>Center ID: 65545
Not incoming Parts in Part
+Part
>Subwoofer ID: 131089
+Part
>Subwoofer ID: 65546
Not incoming Parts in Part
+Part
>Rear ID: 131090
+Part
>Rear ID: 65547
Not incoming Parts in Part
+Part
>Front ID: 131091
+Part
>Front ID: 65548
Not incoming Parts in Part

 

Any help is appreciated. Thx

Edited by Seminko
Link to comment
Share on other sites

Link to comment
Share on other sites

I think the issue is that It's not creating the IAudioMute Interface. Probably is not supported at least using that way. try this code and show the SciTE console output.

 

Opt("MustDeclareVars", 1)

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $E_NOTFOUND = 0x80070490
Global Const $S_OK = 0

Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"


Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}"
Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _
        "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)"


Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}"
Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _
        "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)"


Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}"
Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _
        "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _
        "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)"

Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}"
Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)"

Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}"
Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)"

MUTE()

Func MUTE()
Local $hr = -1

Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then
    ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF)
    Exit
EndIf

Local $pDevice = 0
$hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice)

If FAILED($hr) Then
    ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
If @error Then
    ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $pDeviceTopology = 0
$hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Device Topology" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf

Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology)

If @error Then
    ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf


Local $pConnEndpoint = 0
$hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting endpoint Connector" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector)
If @error Then
    ConsoleWrite("!Error Creating IConnector Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pConnDevice = 0
$hr = $oIConnector.GetConnectedTo($pConnDevice)
If FAILED($hr) Then
    ConsoleWrite("!Error GetConnectedTo Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector)

If @error Then
    ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pPart = 0
$hr = $oConnDevice.QueryInterface($IID_IPart, $pPart)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Part" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    $oConnDevice = 0
    Exit
EndIf

Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart)
If @error Then
    ConsoleWrite("!Error Creating IPart Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF)
GetPart($oIPart)
$oIPart = 0
EndFunc

Func GetPart(ByRef $oIPart)
    Local $sPartName = ""
    Local $PartLocalId = ""
    Local $hr = -1
    ConsoleWrite("+Part" & @CRLF)

    $hr = $oIPart.GetName($sPartName)
    If FAILED($hr) Then
        ConsoleWrite("Not Part Name" & @CRLF)
        Return $hr
    EndIf

    $oIPart.GetLocalId($PartLocalId)
    If FAILED($hr) Then
        ConsoleWrite("Not Part ID" & @CRLF)
        Return $hr
    EndIf

    ConsoleWrite("-" & $sPartName & @CRLF)
    ConsoleWrite("-ID: " & $PartLocalId & @CRLF)

    If StringInStr($sPartName, "Pink") or StringInStr($sPartName, "mic") Then
        Local $pIAudioMute = 0
        Local $bMute = 0
        Local $oIAudioMute = 0
        $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute)
        ConsoleWrite( (SUCCEEDED($hr) ? "+SUCCESS: " : "!FAIL: ") &  "IAudioMute" & @CRLF)
        If SUCCEEDED($hr) Then
            $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute)
            If @error Then
                ConsoleWrite("!Error Creating IAudioMute Interface")
            EndIf
            $hr = $oIAudioMute.GetMute($bMute)
            If FAILED($hr) Then
                ConsoleWrite("!Error Getting Mute State" & @CRLF)
            EndIf
            $hr = $oIAudioMute.SetMute(Not ($bMute), Null)
            If SUCCEEDED($hr) Then
                ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF)
                TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1)
                Sleep(2000)
            EndIf
        EndIf
    EndIf

    Local $pIncomingParts = 0
    $hr = $oIPart.EnumPartsIncoming($pIncomingParts)
    If ($hr = $E_NOTFOUND) Then
        ConsoleWrite("Not incoming Parts in Part" & @CRLF)
        Return $S_OK
    EndIf

    If FAILED($hr) Then
        ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF)
        Return $hr
    EndIf

    Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList)
    If @error Then
        ConsoleWrite("!Error Creating IPartsList Interface")
    EndIf

    Local $iNParts = 0
    $oIPartsList.GetCount($iNParts)

    If FAILED($hr) Then
        ConsoleWrite("Couldn't get count of incoming parts")
        Return $hr
    EndIf

    Local $pIncomingPart = 0
    Local $oIPart2 = 0
    For $i = 0 To $iNParts - 1
        $hr = $oIPartsList.GetPart($i, $pIncomingPart)
        If (FAILED($hr)) Then
            ConsoleWrite("Not Got Part" & @CRLF)
            $oIPartsList = 0
            Return $hr
        EndIf
        Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart)
        If @error Then
            ConsoleWrite("!Error Creating IPartsList(2) Interface")
            $oIPartsList = 0
            Return $hr
        EndIf

        $hr = GetPart($oIPart2)
        If FAILED($hr) Then
            $oIPartsList = 0
            $oIPart2 = 0
            Return $hr
        EndIf
    Next
    $oIPart2=0
    Return $S_OK
EndFunc   ;==>GetPart



Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

Saludos

Link to comment
Share on other sites

Here's the output:

Spoiler


>>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<
+Part
-Realtek HD Audio output
-ID: 65537
+Part
-Celkové ztlumení
-ID: 131073
+Part
-Reproduktory
-ID: 131072
+Part
-Sum
-ID: 131074
+Part
-
-ID: 65536
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131075
+Part
-Rear Black In
-ID: 131076
+Part
-Rear Black In
-ID: 65538
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131077
+Part
-Rear Orange In
-ID: 131078
+Part
-Rear Orange In
-ID: 65539
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131079
+Part
-Rear Pink In
-ID: 131080
!FAIL: IAudioMute
+Part
-Rear Pink In
-ID: 65540
!FAIL: IAudioMute
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131081
+Part
-Front Pink In
-ID: 131082
!FAIL: IAudioMute
+Part
-Front Pink In
-ID: 65541
!FAIL: IAudioMute
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131083
+Part
-Rear Blue In
-ID: 131084
+Part
-Rear Blue In
-ID: 65542
Not incoming Parts in Part
+Part
-Ztlumit
-ID: 131085
+Part
-Front Green In
-ID: 131086
+Part
-Front Green In
-ID: 65543
Not incoming Parts in Part
+Part
-Side
-ID: 131087
+Part
-Side
-ID: 65544
Not incoming Parts in Part
+Part
-Center
-ID: 131088
+Part
-Center
-ID: 65545
Not incoming Parts in Part
+Part
-Subwoofer
-ID: 131089
+Part
-Subwoofer
-ID: 65546
Not incoming Parts in Part
+Part
-Rear
-ID: 131090
+Part
-Rear
-ID: 65547
Not incoming Parts in Part
+Part
-Front
-ID: 131091
+Part
-Front
-ID: 65548
Not incoming Parts in Part


 

 

Link to comment
Share on other sites

As I was thinking the issue is that the IAudioMute interface can't be created. I'll look deep on this later.

 

Saludos

Link to comment
Share on other sites

Seems to be Windows 10 enumerates in a diferent way...

I think this should work:

Opt("MustDeclareVars", 1)

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $E_NOTFOUND = 0x80070490
Global Const $S_OK = 0

Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"


Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}"
Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _
        "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)"


Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}"
Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _
        "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)"


Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}"
Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _
        "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _
        "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)"

Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}"
Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)"

Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}"
Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)"

MUTE()

Func MUTE()
Local $hr = -1

Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then
    ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF)
    Exit
EndIf

Local $pDevice = 0
$hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice)

If FAILED($hr) Then
    ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
If @error Then
    ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $pDeviceTopology = 0
$hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Device Topology" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf

Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology)

If @error Then
    ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf


Local $pConnEndpoint = 0
$hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting endpoint Connector" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector)
If @error Then
    ConsoleWrite("!Error Creating IConnector Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pConnDevice = 0
$hr = $oIConnector.GetConnectedTo($pConnDevice)
If FAILED($hr) Then
    ConsoleWrite("!Error GetConnectedTo Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector)

If @error Then
    ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pPart = 0
$hr = $oConnDevice.QueryInterface($IID_IPart, $pPart)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Part" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    $oConnDevice = 0
    Exit
EndIf

Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart)
If @error Then
    ConsoleWrite("!Error Creating IPart Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF)
GetPart($oIPart)
$oIPart = 0
EndFunc

Func GetPart(ByRef $oIPart)
    Local Static $iIndex=0
    Local $sPartName = ""
    Local $PartLocalId = ""
    Local $hr = -1
    ConsoleWrite("+Part" & @CRLF)

    $hr = $oIPart.GetName($sPartName)
    If FAILED($hr) Then
        ConsoleWrite("Not Part Name" & @CRLF)
        Return $hr
    EndIf

    $oIPart.GetLocalId($PartLocalId)
    If FAILED($hr) Then
        ConsoleWrite("Not Part ID" & @CRLF)
        Return $hr
    EndIf

    ConsoleWrite(">" & $sPartName)
    ConsoleWrite(" ID: " & $PartLocalId & @CRLF)

    If True Then
        Local $pIAudioMute = 0
        Local $bMute = 0
        Local $oIAudioMute = 0
        $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute)
        If   SUCCEEDED($hr) Then $iIndex+=1
        If SUCCEEDED($hr) And $iIndex=4 Then
            $iIndex=0
            $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute)
            If @error Then
                ConsoleWrite("!Error Creating IAudioMute Interface")
            EndIf
            $hr = $oIAudioMute.GetMute($bMute)
            If FAILED($hr) Then
                ConsoleWrite("!Error Getting Mute State" & @CRLF)
            EndIf
            $hr = $oIAudioMute.SetMute(Not ($bMute), Null)
            If SUCCEEDED($hr) Then
                ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF)
                TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1)
                Sleep(2000)
            EndIf
        EndIf
    EndIf

    Local $pIncomingParts = 0
    $hr = $oIPart.EnumPartsIncoming($pIncomingParts)
    If ($hr = $E_NOTFOUND) Then
        ConsoleWrite("Not incoming Parts in Part" & @CRLF)
        Return $S_OK
    EndIf

    If FAILED($hr) Then
        ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF)
        Return $hr
    EndIf

    Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList)
    If @error Then
        ConsoleWrite("!Error Creating IPartsList Interface")
    EndIf

    Local $iNParts = 0
    $oIPartsList.GetCount($iNParts)

    If FAILED($hr) Then
        ConsoleWrite("Couldn't get count of incoming parts")
        Return $hr
    EndIf

    Local $pIncomingPart = 0
    Local $oIPart2 = 0
    For $i = 0 To $iNParts - 1
        $hr = $oIPartsList.GetPart($i, $pIncomingPart)
        If (FAILED($hr)) Then
            ConsoleWrite("Not Got Part" & @CRLF)
            $oIPartsList = 0
            Return $hr
        EndIf
        Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart)
        If @error Then
            ConsoleWrite("!Error Creating IPartsList(2) Interface")
            $oIPartsList = 0
            Return $hr
        EndIf

        $hr = GetPart($oIPart2)
        If FAILED($hr) Then
            $oIPartsList = 0
            $oIPart2 = 0
            Return $hr
        EndIf
    Next
    $oIPart2=0
    Return $S_OK
EndFunc   ;==>GetPart



Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

Saludos

Link to comment
Share on other sites

Aaaand I spoke a bit too soon ;)

When I call the function muliple times it doesn't affect the mic only but rather all the "inputs", and it does that in this order:

image.png.0462c840ddab207b382c406cd82c1d47.png

So the first run, it correctly mutes Rear Pink In, which is where my mic is. Then the Front Pink in, black and finally orange which do nothing. After which is unmutes the Rear Pink In (mic) but only the icon changes (the mic is not muted in reality), however without running it again, it unmutes Front Pink in as well which then in reality unmutes the mic

Edited by Seminko
grammar
Link to comment
Share on other sites

Link to comment
Share on other sites

After i read all the posts, i thought the op was talking about the feature "listen to this device" as seen on this screenshot.

 

screenshot - 23072018-0335.jpg

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

12 hours ago, careca said:

After i read all the posts, i thought the op was talking about the feature "listen to this device" as seen on this screenshot.

Nope, that's a different thing. Similar, yes, but not the same.

Link to comment
Share on other sites

The strange thing is that when I close the script after each mute, it works correctly. But when I have a while loop going with sleep, calling the Mute function by a hotkey, the above mentioned behavior appears...

 

Something with the variables maybe? I guess, if there was a way to reset them after each call, that would solve the problem? If that is a solution we want, that is...

Edited by Seminko
Link to comment
Share on other sites

Link to comment
Share on other sites

14 hours ago, Danyfirex said:

Seminko please post the way you use the script.

Saludos

Here it is:

Opt("MustDeclareVars", 1)

; *** SEMINKO ADDED THIS ******
HotKeySet("{F9}", "Mute")
; *****************************

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $E_NOTFOUND = 0x80070490
Global Const $S_OK = 0

Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"


Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}"
Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _
        "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)"


Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}"
Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _
        "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)"


Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}"
Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _
        "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _
        "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)"

Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}"
Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)"

Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}"
Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)"


; *** SEMINKO ADDED THIS ******
While 1
    Sleep(250)
WEnd
; *****************************

Func MUTE()
Local $hr = -1

Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
If @error Then
    ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF)
    Exit
EndIf

Local $pDevice = 0
$hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice)

If FAILED($hr) Then
    ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
If @error Then
    ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    Exit
EndIf


Local $pDeviceTopology = 0
$hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Device Topology" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf

Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology)

If @error Then
    ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    Exit
EndIf


Local $pConnEndpoint = 0
$hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting endpoint Connector" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector)
If @error Then
    ConsoleWrite("!Error Creating IConnector Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pConnDevice = 0
$hr = $oIConnector.GetConnectedTo($pConnDevice)
If FAILED($hr) Then
    ConsoleWrite("!Error GetConnectedTo Device" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector)

If @error Then
    ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


Local $pPart = 0
$hr = $oConnDevice.QueryInterface($IID_IPart, $pPart)
If FAILED($hr) Then
    ConsoleWrite("!Error Getting Part" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    $oConnDevice = 0
    Exit
EndIf

Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart)
If @error Then
    ConsoleWrite("!Error Creating IPart Interface" & @CRLF)
    $oMMDeviceEnumerator = 0
    $oMMDevice = 0
    $oDeviceTopology = 0
    Exit
EndIf


ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF)
GetPart($oIPart)
$oIPart = 0
EndFunc

Func GetPart(ByRef $oIPart)
    Local Static $iIndex=0
    Local $sPartName = ""
    Local $PartLocalId = ""
    Local $hr = -1
    ConsoleWrite("+Part" & @CRLF)

    $hr = $oIPart.GetName($sPartName)
    If FAILED($hr) Then
        ConsoleWrite("Not Part Name" & @CRLF)
        Return $hr
    EndIf

    $oIPart.GetLocalId($PartLocalId)
    If FAILED($hr) Then
        ConsoleWrite("Not Part ID" & @CRLF)
        Return $hr
    EndIf

    ConsoleWrite(">" & $sPartName)
    ConsoleWrite(" ID: " & $PartLocalId & @CRLF)

    If True Then
        Local $pIAudioMute = 0
        Local $bMute = 0
        Local $oIAudioMute = 0
        $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute)
        If   SUCCEEDED($hr) Then $iIndex+=1
        If SUCCEEDED($hr) And $iIndex=4 Then
            $iIndex=0
            $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute)
            If @error Then
                ConsoleWrite("!Error Creating IAudioMute Interface")
            EndIf
            $hr = $oIAudioMute.GetMute($bMute)
            If FAILED($hr) Then
                ConsoleWrite("!Error Getting Mute State" & @CRLF)
            EndIf
            $hr = $oIAudioMute.SetMute(Not ($bMute), Null)
            If SUCCEEDED($hr) Then
                ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF)
                TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1)
                Sleep(2000)
            EndIf
        EndIf
    EndIf

    Local $pIncomingParts = 0
    $hr = $oIPart.EnumPartsIncoming($pIncomingParts)
    If ($hr = $E_NOTFOUND) Then
        ConsoleWrite("Not incoming Parts in Part" & @CRLF)
        Return $S_OK
    EndIf

    If FAILED($hr) Then
        ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF)
        Return $hr
    EndIf

    Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList)
    If @error Then
        ConsoleWrite("!Error Creating IPartsList Interface")
    EndIf

    Local $iNParts = 0
    $oIPartsList.GetCount($iNParts)

    If FAILED($hr) Then
        ConsoleWrite("Couldn't get count of incoming parts")
        Return $hr
    EndIf

    Local $pIncomingPart = 0
    Local $oIPart2 = 0
    For $i = 0 To $iNParts - 1
        $hr = $oIPartsList.GetPart($i, $pIncomingPart)
        If (FAILED($hr)) Then
            ConsoleWrite("Not Got Part" & @CRLF)
            $oIPartsList = 0
            Return $hr
        EndIf
        Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart)
        If @error Then
            ConsoleWrite("!Error Creating IPartsList(2) Interface")
            $oIPartsList = 0
            Return $hr
        EndIf

        $hr = GetPart($oIPart2)
        If FAILED($hr) Then
            $oIPartsList = 0
            $oIPart2 = 0
            Return $hr
        EndIf
    Next
    $oIPart2=0
    Return $S_OK
EndFunc   ;==>GetPart



Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

 

EDIT: btw, I was using a hotkey like this in the previous version of the code from four years ago. It worked probably because the mic was being checked by name? In this new script it looks, at least to me, that we check if the name and ID was found, regardless of what those are.

Edited by Seminko
Link to comment
Share on other sites

Hello. It's Code work correcly for me. anyway here is a mod. let me know if it works for you.

Opt("MustDeclareVars", 1)

; *** SEMINKO ADDED THIS ******
HotKeySet("{F9}", "Mute")
; *****************************

Global Enum $eRender, $eCapture, $eAll, $EDataFlow_enum_count
Global Enum $eConsole, $eMultimedia, $eCommunications, $ERole_enum_count
Global Const $CLSCTX_INPROC_SERVER = 1
Global Const $E_NOTFOUND = 0x80070490
Global Const $S_OK = 0

Global Const $CLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $IID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = _
        "EnumAudioEndpoints hresult(int;dword;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr)"


Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = _
        "Activate hresult(struct*;dword;ptr;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(wstr*);" & _
        "GetState hresult(dword*)"


Global Const $IID_IDeviceTopology = "{2A07407E-6497-4A18-9787-32F79BD0D98F}"
Global Const $tagIDeviceTopology = "GetConnectorCount hresult(int*);GetConnector hresult(int;ptr*);" & _
        "GetSubunitCount hresult(int*);GetSubunit hresult(int;ptr*);GetPartById hresult(int,ptr*);GetDeviceId hresult(ptr*);GetSignalPath hresult(ptr;ptr;bool;ptr*)"


Global Const $IID_IConnector = "{9c2c4058-23f5-41de-877a-df3af236a09e}"
Global Const $tagIConnector = "GetType hresult(ptr*);GetDataFlow hresult(ptr*);ConnectTo hresult(ptr);Disconnect hresult(none);IsConnected hresult(int*);" & _
        "GetConnectedTo hresult(ptr*);GetConnectorIdConnectedTo hresult(wstr*);GetDeviceIdConnectedTo hresult(wstr*)"


Global Const $IID_IPart = "{AE2DE0E4-5BCA-4F2D-AA46-5D13F8FDB3A9}"
Global Const $tagIPart = "GetName hresult(wstr*);GetLocalId hresult(uint*);GetGlobalId hresult(wstr*);GetPartType hresult(ptr);GetSubType hresult(ptr);" & _
        "GetControlInterfaceCount hresult(uint*);GetControlInterface hresult(int;ptr*);EnumPartsIncoming hresult(ptr*);EnumPartsOutgoing hresult(ptr*);" & _
        "GetTopologyObject hresult(ptr*);Activate hresult(dword;struct*;ptr*);RegisterControlChangeCallback hresult(ptr);UnregisterControlChangeCallback hresult(ptr)"

Global Const $IID_IPartsList = "{6DAA848C-5EB0-45CC-AEA5-998A2CDA1FFB}"
Global Const $tagIPartsList = "GetCount hresult(uint*);GetPart hreuslt(uint;ptr*)"

Global Const $IID_IAudioMute = "{DF45AEEA-B74A-4B6B-AFAD-2366B6AA012E}"
Global Const $tagIAudioMute = "SetMute hresult(bool;ptr);GetMute hresult(int*)"


; *** SEMINKO ADDED THIS ******
While 1
    Sleep(250)
WEnd
; *****************************

Func MUTE()
    Local $hr = -1

    Local $oMMDeviceEnumerator = ObjCreateInterface($CLSID_MMDeviceEnumerator, $IID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)
    If @error Then
        ConsoleWrite("!Error Creating IMMDeviceEnumerator Interface" & @CRLF)
        Exit
    EndIf

    Local $pDevice = 0
    $hr = $oMMDeviceEnumerator.GetDefaultAudioEndpoint($eRender, $eConsole, $pDevice)

    If FAILED($hr) Then
        ConsoleWrite("!Error Getting Default Render Endpoint Device" & @CRLF)
        $oMMDeviceEnumerator = 0
        Exit
    EndIf


    Local $oMMDevice = ObjCreateInterface($pDevice, $IID_IMMDevice, $tagIMMDevice)
    If @error Then
        ConsoleWrite("!Error Creating IMMDevice Interface" & @CRLF)
        $oMMDeviceEnumerator = 0
        Exit
    EndIf


    Local $pDeviceTopology = 0
    $hr = $oMMDevice.Activate(__uuidof($IID_IDeviceTopology), $CLSCTX_INPROC_SERVER, 0, $pDeviceTopology)
    If FAILED($hr) Then
        ConsoleWrite("!Error Getting Device Topology" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        Exit
    EndIf

    Local $oDeviceTopology = ObjCreateInterface($pDeviceTopology, $IID_IDeviceTopology, $tagIDeviceTopology)

    If @error Then
        ConsoleWrite("!Error Creating IDeviceTopology Interface" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        Exit
    EndIf


    Local $pConnEndpoint = 0
    $hr = $oDeviceTopology.GetConnector(0, $pConnEndpoint)
    If FAILED($hr) Then
        ConsoleWrite("!Error Getting endpoint Connector" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        Exit
    EndIf


    Local $oIConnector = ObjCreateInterface($pConnEndpoint, $IID_IConnector, $tagIConnector)
    If @error Then
        ConsoleWrite("!Error Creating IConnector Interface" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        Exit
    EndIf


    Local $pConnDevice = 0
    $hr = $oIConnector.GetConnectedTo($pConnDevice)
    If FAILED($hr) Then
        ConsoleWrite("!Error GetConnectedTo Device" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        Exit
    EndIf


    Local $oConnDevice = ObjCreateInterface($pConnDevice, $IID_IConnector, $tagIConnector)

    If @error Then
        ConsoleWrite("!Error Creation oConnDevice(IConnector) Interface" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        Exit
    EndIf


    Local $pPart = 0
    $hr = $oConnDevice.QueryInterface($IID_IPart, $pPart)
    If FAILED($hr) Then
        ConsoleWrite("!Error Getting Part" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        $oConnDevice = 0
        Exit
    EndIf

    Local $oIPart = ObjCreateInterface($pPart, $IID_IPart, $tagIPart)
    If @error Then
        ConsoleWrite("!Error Creating IPart Interface" & @CRLF)
        $oMMDeviceEnumerator = 0
        $oMMDevice = 0
        $oDeviceTopology = 0
        Exit
    EndIf


    ConsoleWrite(">>>>>>>>>>>>>>>>>BEGIN<<<<<<<<<<<<<<<<<<<<" & @CRLF)
    GetPart($oIPart)
    $oIPart = 0
EndFunc   ;==>MUTE

Func GetPart(ByRef $oIPart)
    Local Static $bNextIsMute = False
    Local $sPartName = ""
    Local $PartLocalId = ""
    Local $hr = -1
    ConsoleWrite("+Part" & @CRLF)

    $hr = $oIPart.GetName($sPartName)
    If FAILED($hr) Then
        ConsoleWrite("Not Part Name" & @CRLF)
        Return $hr
    EndIf

    $oIPart.GetLocalId($PartLocalId)
    If FAILED($hr) Then
        ConsoleWrite("Not Part ID" & @CRLF)
        Return $hr
    EndIf

    ConsoleWrite(">" & $sPartName)
    ConsoleWrite(" ID: " & $PartLocalId & @CRLF)


    If $bNextIsMute=False Then
        $bNextIsMute = StringInStr($sPartName, 'Front Pink In') ? True : False
    EndIf
    If $bNextIsMute Then
        Local $pIAudioMute = 0
        Local $bMute = 0
        Local $oIAudioMute = 0
        $hr = $oIPart.Activate($CLSCTX_INPROC_SERVER, __uuidof($IID_IAudioMute), $pIAudioMute)
        If SUCCEEDED($hr) Then
            $bNextIsMute = False
            $oIAudioMute = ObjCreateInterface($pIAudioMute, $IID_IAudioMute, $tagIAudioMute)
            If @error Then
                ConsoleWrite("!Error Creating IAudioMute Interface")
            EndIf
            $hr = $oIAudioMute.GetMute($bMute)
            If FAILED($hr) Then
                ConsoleWrite("!Error Getting Mute State" & @CRLF)
            EndIf
            $hr = $oIAudioMute.SetMute(Not ($bMute), Null)
            If SUCCEEDED($hr) Then
                ConsoleWrite("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!") & @CRLF)
                TrayTip("!MUTE: " & (($bMute = False) ? "ON!" : "OFF!"), "Danyfirex", 2, 1)
                Sleep(2000)
            EndIf
        EndIf
    EndIf

    Local $pIncomingParts = 0
    $hr = $oIPart.EnumPartsIncoming($pIncomingParts)
    If ($hr = $E_NOTFOUND) Then
        ConsoleWrite("Not incoming Parts in Part" & @CRLF)
        Return $S_OK
    EndIf

    If FAILED($hr) Then
        ConsoleWrite("!ERROR Enumerating incoming Parts" & @CRLF)
        Return $hr
    EndIf

    Local $oIPartsList = ObjCreateInterface($pIncomingParts, $IID_IPartsList, $tagIPartsList)
    If @error Then
        ConsoleWrite("!Error Creating IPartsList Interface")
    EndIf

    Local $iNParts = 0
    $oIPartsList.GetCount($iNParts)

    If FAILED($hr) Then
        ConsoleWrite("Couldn't get count of incoming parts")
        Return $hr
    EndIf

    Local $pIncomingPart = 0
    Local $oIPart2 = 0
    For $i = $iNParts - 1 To 0 Step -1
        $hr = $oIPartsList.GetPart($i, $pIncomingPart)
        If (FAILED($hr)) Then
            ConsoleWrite("Not Got Part" & @CRLF)
            $oIPartsList = 0
            Return $hr
        EndIf
        Local $oIPart2 = ObjCreateInterface($pIncomingPart, $IID_IPart, $tagIPart)
        If @error Then
            ConsoleWrite("!Error Creating IPartsList(2) Interface")
            $oIPartsList = 0
            Return $hr
        EndIf

        $hr = GetPart($oIPart2)
        If FAILED($hr) Then
            $oIPartsList = 0
            $oIPart2 = 0
            Return $hr
        EndIf
    Next
    $oIPart2 = 0
    Return $S_OK
EndFunc   ;==>GetPart



Func __uuidof($sGUID)
    Local $tGUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]")
    DllCall("ole32.dll", "long", "CLSIDFromString", "wstr", $sGUID, "struct*", $tGUID)
    If @error Then Return SetError(@error, @extended, 0)
    Return $tGUID
EndFunc   ;==>__uuidof

Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Func FAILED($hr)
    Return ($hr < 0)
EndFunc   ;==>FAILED

Saludos

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...