-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenRGBMonitorStatus.ps1
More file actions
60 lines (53 loc) · 2.22 KB
/
Copy pathopenRGBMonitorStatus.ps1
File metadata and controls
60 lines (53 loc) · 2.22 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
$logStatus = 0 # Set to 0 to DISABLE LOGGING
$logFile = Join-Path -Path $PSScriptRoot -ChildPath "monitor_status.log"
$shortcutOff = Join-Path -Path $PSScriptRoot -ChildPath "OpenRGB OFF.lnk"
$shortcutOn = Join-Path -Path $PSScriptRoot -ChildPath "OpenRGB ON.lnk"
if ($logStatus -eq 1) {
"--- Monitor WMI Logger Started at $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ---" | Out-File -FilePath $logFile -Append
}
$previousState = $null # null, "on", or "off"
while ($true) {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$currentState = $null
try {
$monitors = Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID -ErrorAction Stop
if ($monitors.Count -eq 0) {
if ($logStatus -eq 1) {
"$timestamp - No WMI monitors detected." | Out-File -FilePath $logFile -Append
}
$currentState = "off"
} else {
foreach ($monitor in $monitors) {
$manufacturer = ([System.Text.Encoding]::ASCII.GetString($monitor.ManufacturerName)).Trim([char]0)
$product = ([System.Text.Encoding]::ASCII.GetString($monitor.ProductCodeID)).Trim([char]0)
$serial = ([System.Text.Encoding]::ASCII.GetString($monitor.SerialNumberID)).Trim([char]0)
if ($logStatus -eq 1) {
"$timestamp - Monitor: $manufacturer $product - Serial: $serial" | Out-File -FilePath $logFile -Append
}
}
$currentState = "on"
}
}
catch {
if ($logStatus -eq 1) {
"$timestamp - WMI query failed: $_" | Out-File -FilePath $logFile -Append
}
$currentState = "off"
}
# Handle state change triggers
if ($currentState -ne $previousState) {
if ($currentState -eq "off" -and (Test-Path $shortcutOff)) {
Start-Process -FilePath $shortcutOff
if ($logStatus -eq 1) {
"$timestamp - Launched: OpenRGB OFF.lnk" | Out-File -FilePath $logFile -Append
}
} elseif ($currentState -eq "on" -and (Test-Path $shortcutOn)) {
Start-Process -FilePath $shortcutOn
if ($logStatus -eq 1) {
"$timestamp - Launched: OpenRGB ON.lnk" | Out-File -FilePath $logFile -Append
}
}
$previousState = $currentState
}
Start-Sleep -Seconds 5
}