-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMSTeamsBlackScreenFix.ps1
154 lines (133 loc) · 3.59 KB
/
MSTeamsBlackScreenFix.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# This script needs admin rights, be sure to run it elevated!
# This script fixes an issue between the new Microsoft Teams and the Nahimic service
# The issue is black screen instead of video/webcam unless minimised
# The script adds 2 processes to the BlackApps.dat file...
function Get-Directories
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true,
ValueFromPipeline = $true,
Position = 0)]
[System.IO.FileInfo]$Path,
[Parameter(Position = 1)]
[String]$SearchPattern = '*.*'
)
Begin
{
# an arraylist to hold the results
$result = New-Object -TypeName System.Collections.ArrayList
# a stack object to push directories that needs to be processed
$pending = New-Object System.Collections.Generic.Stack[String]
}
Process
{
# push all provided paths to the stack
foreach ($entry in $Path)
{
$pending.Push($entry)
}
# loop through the stack
while ($pending.Count -ne 0)
{
# current item to process
$current = $pending.Pop()
try
{
# get all subdirectories from the current one
# handle in try..catch e.g. to catch Access Denied
$next = [IO.Directory]::GetDirectories($current, $SearchPattern)
if ($null -ne $next)
{
ForEach ($dir in $next)
{
# add directory to the result list
[void]$result.Add($dir)
}
}
}
# ignore exceptions
catch { }
try
{
# we need to call GetDirectories for all directories that we found
$next = [IO.Directory]::GetDirectories($current, $SearchPattern)
ForEach ($dir in $next)
{
# push subdir to stack
$pending.Push($dir)
}
}
# ignore exceptions
catch { }
}
}
End
{
return $result
}
}
function Find-BlackAppsDat {
# Get the ProgramData path dynamically
$programDataPath = [Environment]::GetFolderPath('CommonApplicationData')
$activity = "Searching for BlackApps.dat"
# get list of folders to search...
# note using Get-Directories as Get-ChildItem bombs out on errors...
$folders = Get-Directories -Path ([System.IO.FileInfo]$programDataPath) | Sort-Object
for ($i= 0 ; $i -lt $folders.Count ; $i++)
{
try
{
# Search for BlackApps.dat
$percentComplete = [int] [Math]::Truncate(($i / $folders.Count) * 100)
Write-Progress -Activity $activity -CurrentOperation $folders[$i] -PercentComplete $percentComplete
$file = Get-ChildItem -Path $folders[$i] -Filter "BlackApps.dat" -ErrorAction Stop
if ($null -ne $file)
{
break
}
}
catch
{
# ignore exception (e.g. access denied) so we can continue to next folder...
}
}
Write-Progress -Activity $activity -Completed
if ($null -ne $file)
{
return $file.FullName
}
}
$blackAppsDatPath = Find-BlackAppsDat
if ($null -ne $blackAppsDatPath)
{
$fileChanged = $false
"Found BlackApps.dat at $blackAppsDatPath"
# Read the file content
$fileContent = Get-Content -Path $blackAppsDatPath
$processNames = @("ms-teams.exe", "msedgewebview2.exe")
# Check if the process name is already in the file
foreach ($processName in $processNames)
{
if ($processName -notin $fileContent) {
# Add the process name to the file
$fileContent += $processName
$fileChanged = $true
Write-Host "$processName added to the file."
} else {
Write-Host "$processName is already in the file."
}
}
if ($fileChanged)
{
$fileContent | Out-File -FilePath $blackAppsDatPath
$serviceName = 'NahimicService'
"Restarting Service $serviceName to update changes..."
Restart-Service -Name $serviceName -Confirm
}
}
else
{
"BlackApps.data was not found!"
}