-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRealtekSoundReset.ps1
115 lines (113 loc) · 3.86 KB
/
RealtekSoundReset.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#Restart realtek hardware for headphone issues
$Error.clear()
#Check if already elevated. Will relaunch elevated if not.
$ElevCheck = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')
if ($ElevCheck -eq $false) {
Start-Process powershell.exe -Verb runas -ArgumentList "-File", "$PSCommandPath"
timeout.exe /t 3
Exit
}
else {
#Check for Realtek sound hardware
$HardwareCheck = (Get-PnpDevice -FriendlyName 'Realtek(R) Audio' -ErrorAction SilentlyContinue)
$HardwareID = $HardwareCheck.InstanceId
if ($HardwareCheck.Problem -eq "CM_PROB_DISABLED") {
Write-Host -ForegroundColor Yellow "Realtek audio device already disabled. Exiting..."
timeout.exe /t 5
Exit
}
if ($Null -eq $HardwareID.Count -or $HardwareID.Count -eq 0) {
Write-Host -ForegroundColor Red "Could not find Realtek audio device..."
Write-Host ""
Pause
Exit
}
$Error.Clear()
#Stop Audio services
Write-Host ""
Write-Host Stopping services...
Write-Host ""
$Audio1 = Get-Service Audiosrv -ErrorAction SilentlyContinue
if ($Audio1.Count -eq 1) {
Stop-Service $Audio1
Write-Host Stopped $Audio1.DisplayName
Write-Host ""
}
$Audio2 = Get-Service AudioEndpointBuilder -ErrorAction SilentlyContinue
if ($Audio2.Count -eq 1) {
Stop-Service $Audio2
Write-Host Stopped $Audio2.DisplayName
Write-Host ""
}
$WaveAudio1 = Get-Service WavesSysSvc -ErrorAction SilentlyContinue
if ($WaveAudio1.Count -eq 1) {
Stop-Service $WaveAudio1
Write-Host Stopped $WaveAudio1.DisplayName
Write-Host ""
}
$WaveAudio2 = Get-Service WavesAudioService -ErrorAction SilentlyContinue
if ($WaveAudio2.count -eq 1) {
Stop-Service $WaveAudio2
Write-Host Stopped $WaveAudio2.DisplayName
Write-Host ""
}
#Disable audio device
Write-Host "Disabling adapter..."
Disable-PnpDevice "$HardwareID" -Confirm:$false -ErrorAction SilentlyContinue
if ($Error.Count -gt 0) {
Write-Host ""
Write-Host -ForegroundColor Red "Issue disabling. Check that nothing besides the system is using sound and then rerun."
SndVol.exe
Write-Host ""
timeout.exe /t 3
Exit
}
else {
#Wait several seconds to allow operation
$Error.Clear()
Write-Host ""
Write-Host -ForegroundColor Green "Disabled successfully!"
timeout.exe /nobreak /t 3
Write-Host ""
#Enable audio device
Write-Host "Enabling adapter..."
Enable-PnpDevice "$HardwareID" -Confirm:$false
Write-Host ""
if ($Error.Count -gt 0) {
Write-Host -ForegroundColor Red "Issue enabling"
Write-Host ""
Pause
Exit
} else {
Write-Host -ForegroundColor Green "Enabled successfully!"
}
timeout /t 3
#Restart servies
}
Write-Host ""
Write-Host Restarting services...
Write-Host ""
if ($Audio1.Count -eq 1) {
Start-Service $Audio1
Write-Host Started $Audio1.DisplayName
Write-Host ""
}
if ($Audio2.Count -eq 1) {
Start-Service $Audio2
Write-Host Started $Audio2.DisplayName
Write-Host ""
}
if ($WaveAudio1.Count -eq 1) {
Start-Service $WaveAudio1
Write-Host Started $WaveAudio1.DisplayName
Write-Host ""
}
if ($WaveAudio2.count -eq 1) {
Start-Service $WaveAudio2
Write-Host Started $WaveAudio2.DisplayName
Write-Host ""
}
Write-Host -ForegroundColor Green Done!
timeout /t 5
Exit
}