Skip to content

Commit 898da51

Browse files
committed
Warn and check if camera access is denied
1 parent 4a7fba2 commit 898da51

4 files changed

Lines changed: 280 additions & 105 deletions

File tree

PSMSVirtualDeviceManager/Classes/ClassVideoInputDevices.vb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Imports System.Runtime.InteropServices
22
Imports System.Runtime.InteropServices.ComTypes
3+
Imports Microsoft.Win32
34

45
Public Class ClassVideoInputDevices
56
Private Class FilterCategory ' uuids.h : CLSID_*
@@ -12,6 +13,32 @@ Public Class ClassVideoInputDevices
1213
Public Shared ReadOnly SystemDeviceEnum As Guid = New Guid(&H62BE5D10, &H60EB, &H11D0, &HBD, &H3B, &H0, &HA0, &HC9, &H11, &HCE, &H86)
1314
End Class
1415

16+
Public Shared Function GetCameraAccessAllowed() As Boolean
17+
Dim mWebcamKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam", False)
18+
Dim mWebcamNonPackagedKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged", False)
19+
20+
Dim sWebcamAllowed As String = TryCast(mWebcamKey.GetValue("Value", Nothing, RegistryValueOptions.None), String)
21+
Dim sWebcamNonPackagedAllowed As String = TryCast(mWebcamNonPackagedKey.GetValue("Value", Nothing, RegistryValueOptions.None), String)
22+
23+
Dim bWebcamAllowed As Boolean = False
24+
Dim bWebcamNonPackagedAllowed As Boolean = False
25+
26+
' Check if Webcams are allowed in general (UWP apps + Win32 apps)
27+
If (sWebcamAllowed IsNot Nothing AndAlso sWebcamAllowed = "Allow") Then
28+
bWebcamAllowed = True
29+
Else
30+
bWebcamAllowed = False
31+
End If
32+
33+
' Check if webcams are allowed for Win32 apps
34+
If (sWebcamNonPackagedAllowed IsNot Nothing AndAlso sWebcamNonPackagedAllowed = "Allow") Then
35+
bWebcamNonPackagedAllowed = True
36+
Else
37+
bWebcamNonPackagedAllowed = False
38+
End If
39+
40+
Return (bWebcamAllowed AndAlso bWebcamNonPackagedAllowed)
41+
End Function
1542

1643
Public Shared Function GetDevicesOfVideoInput(ByRef mDeviceList As List(Of ClassDeviceInfo)) As Boolean
1744
Return GetDevicesOfVideoInputInternal(FilterCategory.VideoInputDevice, mDeviceList)

0 commit comments

Comments
 (0)