forked from ThomasMarcussen/assortedScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonitorRegistryChanges.ps1
32 lines (25 loc) · 1.18 KB
/
MonitorRegistryChanges.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
###################################################################################################################
# Name: MonitorRegistryChanges.ps1
# Author: Thomas Marcussen, [email protected]
# Date: December,2022
###################################################################################################################
# Monitor the registry for changes
# Define the registry key to monitor
$regKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
# Create a new RegistryWatcher object
$watcher = New-Object -TypeName System.Management.ManagementEventWatcher `
-ArgumentList "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='$regKey'"
# Define a callback function to handle registry change events
function OnRegistryChange {
param($source, $eventArgs)
# Print the registry key that was changed
Write-Host "Registry key changed: $($eventArgs.NewEvent.KeyPath)"
}
# Register the callback function to handle registry change events
$watcher.EventArrived += { OnRegistryChange $watcher $_ }
# Start monitoring the registry for changes
$watcher.Start()
# Wait indefinitely
while ($true) {
Start-Sleep -Seconds 1
}