-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsteam.go
52 lines (40 loc) · 1.19 KB
/
steam.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
package main
import (
"fmt"
"os/exec"
"golang.org/x/sys/windows/registry"
)
func switchAccount(account *Account) error {
_ = stopSteam()
reg, err := getRegistry()
if err != nil {
return fmt.Errorf("could not get registry: %w", err)
}
if err := reg.SetStringValue("AutoLoginUser", account.Username); err != nil {
return fmt.Errorf("failed to set value in registry: %w", err)
}
if err := reg.SetDWordValue("RememberPassword", 1); err != nil {
return fmt.Errorf("failed to set value in registry: %w", err)
}
return startSteam()
}
func getActiveUsername() (string, error) {
reg, err := getRegistry()
if err != nil {
return "", fmt.Errorf("could not get registry: %w", err)
}
username, _, err := reg.GetStringValue("AutoLoginUser")
if err != nil {
return "", fmt.Errorf("could not get value in registry: %w", err)
}
return username, nil
}
func getRegistry() (registry.Key, error) {
return registry.OpenKey(registry.CURRENT_USER, `Software\Valve\Steam`, registry.READ|registry.WRITE)
}
func startSteam() error {
return exec.Command("cmd", "/C", "start", "steam://open/main").Start()
}
func stopSteam() error {
return exec.Command("taskkill", "/F", "/IM", "steam.exe").Run()
}