# Copyright © 2015, Microsoft Corporation. All rights reserved. . .\CL_SpeechUtil.ps1 . .\CL_RegSnapin.ps1 ## ## Determine entry point ## $EntryPoint = Get-DiagInput -id IT_EntryPoint ## ## Microphone status values ## $DEFAULT_MIC_OK = 0 $DEFAULT_MIC_NOT_FOUND = 1 $DEFAULT_MIC_DISCONNECTED = 2 $DEFAULT_MIC_MUTED = 3 $DEFAULT_MIC_DISABLED = 4 ## ## Get default microphone status ## Function Get-DefaultMicrophoneStatus() { $type = "microphone/headset microphone" [string]$id = $null [string]$dll = "$env:windir\diagnostics\system\audio\AudioDiagnosticSnapIn.dll" [string]$namespace = "AudioDiagCommandSnapin" [int]$result = $DEFAULT_MIC_UNKNOWN [bool]$DefaultMicSet = $false [bool]$DefaultMicMuted = $false [bool]$DefaultMicEnabled = $false [bool]$DefaultMicConnected = $false $DefaultMicDevice = $null $DefaultMicDeviceInfo = $null try { RegSnapin $dll $namespace ## ## Get all audio capture devices ## [Array]$AudioDevices = $null Parse-List $type | ForEach-Object { if (-not([String]::IsNullOrEmpty($type))) { $AudioDevices += Get-AudioDevice -typename "$_" } } ## ## Get the default device ## foreach ($InputDevice in $AudioDevices) { $DeviceInfo = Get-AudioDevice -id $InputDevice.DeviceID try{ if ($DeviceInfo.IsDefaultAudioDevice("") -eq $true) { $DefaultMicSet = $true $DefaultMicDevice = $InputDevice $DefaultMicDeviceInfo = $DeviceInfo break } } catch { $result = $DEFAULT_MIC_NOT_FOUND } } ## ## Test the default mic for known problems ## if ($DefaultMicSet -eq $true) { ## ## Is Mic Connected ## $DefaultMicConnected = -not(($DefaultMicDeviceInfo.State -band 8) -eq 8) if ($DefaultMicConnected -eq $false) { return $DEFAULT_MIC_DISCONNECTED } ## ## Is Mic Muted ## $DefaultMicMuted = $defaultmicdeviceInfo.mute if ($DefaultmicMuted -eq $true) { return $DEFAULT_MIC_MUTED } ## ## Is Mic Enabled ## $DefaultMicEnabled = -not(($defaultmicdeviceInfo.State -band 2) -eq 2) if ($DefaultMicEnabled -eq $false) { return $DEFAULT_MIC_DISABLED } $result = $DEFAULT_MIC_OK } else { ## ## No default microphone found ## $result = $DEFAULT_MIC_NOT_FOUND } } finally { UnregSnapin $dll $namespace } return $result } ## ## function to check whether current package is running on remote session ## function CheckRemoteSession { [string]$sourceCode = @" using System; using System.Runtime.InteropServices; namespace Microsoft.Windows.Diagnosis { public static class RemoteManager { private const int SM_REMOTESESSION = 0x1000; [DllImport("User32.dll", CharSet = CharSet.Unicode)] private static extern int GetSystemMetrics(int Index); public static bool Remote() { return (0 != GetSystemMetrics(SM_REMOTESESSION)); } } } "@ $type = Add-Type -TypeDefinition $sourceCode -PassThru return $type::Remote() } ## ## Get default microphone status; default mic needs to be healty for calibration ## $MicStatus = Get-DefaultMicrophoneStatus ## ## Don't check calibration unless the default mic is healthy ## if ($MicStatus -eq $DEFAULT_MIC_OK) { ## ## No microphone problems found ## Update-DiagRootCause -id "RC_MicrophoneNotFound" -detected $false ## ## Get the current mic level for verification ## $DefaultMicLevel = Get-DefaultMicrophoneLevel ## ## Get customers permission to calibrate if there is a microphone ## $DoCalibration = Get-CalibrationConsent Update-DiagRootCause -id "RC_CalibrationRequired" -Parameter @{"CalibrationReason"="$entryPoint";"CalibrationConsent"="$DoCalibration";"DefaultMicLevel"="$DefaultMicLevel"} -Detected $DoCalibration } else { ## ## Default mic isn't usable; let audio troubleshooter try to fix it ## Update-DiagRootCause -id "RC_MicrophoneNotFound" -instanceid $MicStatus -detected $true -parameter @{"IsMicPresent"="$false"} }