-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWindowsHelloCameraControl.ps1
More file actions
169 lines (147 loc) · 5.4 KB
/
Copy pathWindowsHelloCameraControl.ps1
File metadata and controls
169 lines (147 loc) · 5.4 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Windows Hello Face ID Camera Control Script
# This script monitors for Windows Hello Face ID activity and controls the front camera access
# Requires Administrator privileges
#Requires -RunAsAdministrator
# Configuration
$logFile = "$env:TEMP\WindowsHelloCameraControl.log"
$checkInterval = 1000 # Check every 1 second (in milliseconds)
# Function to write to log
function Write-Log {
param($Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp - $Message"
Add-Content -Path $logFile -Value $logEntry
Write-Host $logEntry
}
# Function to get front camera device
function Get-FrontCameraDevice {
try {
$frontCamera = Get-PnpDevice -Class Camera -Status OK | Where-Object {
$_.FriendlyName -match "Front|Integrated" -and
$_.FriendlyName -notmatch "Hello|IR|Infrared"
}
return $frontCamera
}
catch {
Write-Log "Error getting front camera device: $($_.Exception.Message)"
return $null
}
}
# Function to disable camera device
function Disable-CameraDevice {
param($device)
try {
Disable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
Write-Log "Disabled camera: $($device.FriendlyName)"
}
catch {
Write-Log "Failed to disable camera $($device.FriendlyName): $($_.Exception.Message)"
}
}
# Function to enable camera device
function Enable-CameraDevice {
param($device)
try {
Enable-PnpDevice -InstanceId $device.InstanceId -Confirm:$false
Write-Log "Enabled camera: $($device.FriendlyName)"
}
catch {
Write-Log "Failed to enable camera $($device.FriendlyName): $($_.Exception.Message)"
}
}
# Function to check if Windows Hello Face ID is active
function Test-WindowsHelloFaceIDActive {
try {
# Check for Windows Hello related processes
$helloProcesses = Get-Process | Where-Object {
$_.ProcessName -match "WinBio|AuthHost|LogonUI|dwm" -or
$_.MainWindowTitle -match "Windows Hello|Face ID|Sign-in"
}
# Check for lock screen state
$lockScreenActive = $false
try {
$lockScreenActive = (Get-Process -Name "LogonUI" -ErrorAction SilentlyContinue) -ne $null
}
catch { }
# Check for authentication UI
$authUIActive = $false
try {
$authUIActive = (Get-Process -Name "AuthHost" -ErrorAction SilentlyContinue) -ne $null
}
catch { }
# Check registry for Windows Hello status (if accessible)
$biometricActive = $false
try {
$biometricService = Get-Service -Name "WbioSrvc" -ErrorAction SilentlyContinue
if ($biometricService -and $biometricService.Status -eq "Running") {
# Check if biometric authentication is in progress
$biometricProcesses = Get-Process | Where-Object {
$_.ProcessName -match "WinBio" -or $_.ProcessName -match "BioIso"
}
$biometricActive = $biometricProcesses.Count -gt 0
}
}
catch { }
return $lockScreenActive -or $authUIActive -or $biometricActive
}
catch {
Write-Log "Error checking Windows Hello status: $($_.Exception.Message)"
return $false
}
}
# Main monitoring function
function Start-CameraMonitoring {
Write-Log "Starting Windows Hello Face ID camera monitoring..."
# Get initial front camera device
$frontCamera = Get-FrontCameraDevice
if (-not $frontCamera) {
Write-Log "No front camera device found. Exiting."
return
}
Write-Log "Found front camera device: $($frontCamera.FriendlyName)"
$wasHelloActive = $false
while ($true) {
try {
$isHelloActive = Test-WindowsHelloFaceIDActive
if ($isHelloActive -and -not $wasHelloActive) {
Write-Log "Windows Hello Face ID activity detected - disabling front camera"
Disable-CameraDevice $frontCamera
$wasHelloActive = $true
}
elseif (-not $isHelloActive -and $wasHelloActive) {
Write-Log "Windows Hello Face ID activity ended - enabling front camera"
Enable-CameraDevice $frontCamera
$wasHelloActive = $false
}
Start-Sleep -Milliseconds $checkInterval
}
catch {
Write-Log "Error in monitoring loop: $($_.Exception.Message)"
Start-Sleep -Milliseconds $checkInterval
}
}
}
# Check if running as administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Main execution
try {
if (-not (Test-Administrator)) {
Write-Host "This script requires Administrator privileges to control camera devices."
Write-Host "Please run PowerShell as Administrator and try again."
exit 1
}
Write-Log "Windows Hello Face ID Camera Control Script started"
Write-Log "Log file: $logFile"
Write-Log "Check interval: $checkInterval ms"
# Start monitoring
Start-CameraMonitoring
}
catch {
Write-Log "Fatal error: $($_.Exception.Message)"
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}