-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
84 lines (69 loc) · 2.24 KB
/
main.go
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
// ElevenTray
// Version: 1.0.2
// Created on: 2024-08-14
// Last Updated: 2024-08-16
// Author: Ray Heffer
// Website: https://lockdown.media
// License: GNU General Public License v3.0
// This program is intended for use on Windows 11 operating systems. For more information, see the README.md file included with this project.
package main
import (
"log"
"os"
"time"
"golang.org/x/sys/windows/registry"
)
func monitorNotifyIconSettings() {
keyPath := `Control Panel\NotifyIconSettings`
k, err := registry.OpenKey(registry.CURRENT_USER, keyPath, registry.QUERY_VALUE|registry.ENUMERATE_SUB_KEYS)
if err != nil {
log.Fatalf("Error opening registry key: %v", err)
}
defer k.Close()
// Check for hidden system tray icons in the registry
for {
subKeys, err := k.ReadSubKeyNames(-1)
if err != nil {
log.Printf("Error reading subkeys: %v", err)
continue
}
for _, subKey := range subKeys {
iconKey, err := registry.OpenKey(k, subKey, registry.SET_VALUE|registry.QUERY_VALUE)
if err != nil {
log.Printf("Error opening subkey: %v", err)
continue
}
// Check current IsPromoted value
currentValue, _, err := iconKey.GetIntegerValue("IsPromoted")
if err != nil || currentValue != 1 {
// Read the ExecutablePath value from the subkey (used to log executable in system tray)
execPath, _, err := iconKey.GetStringValue("ExecutablePath")
if err != nil {
execPath = "Unknown"
}
err = iconKey.SetDWordValue("IsPromoted", 1)
if err != nil {
log.Printf("Error setting IsPromoted for subkey %s: %v", subKey, err)
} else {
log.Printf("Set IsPromoted=1 for subkey %s (ExecutablePath: %s)", subKey, execPath)
}
}
iconKey.Close()
}
time.Sleep(10 * time.Second) // Run check every 10 seconds
}
}
func main() {
// Open (or create) log file in the current directory
logFilePath := "ElevenTray.log"
f, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Error opening log file: %v", err)
}
defer f.Close()
log.SetOutput(f)
log.Println("Starting ElevenTray")
defer log.Println("Process terminated!")
// Start monitoring
monitorNotifyIconSettings()
}