-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.09 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
package main
import (
"fmt"
"os"
"path/filepath"
"golang.org/x/sys/windows/registry"
)
func main() {
if len(os.Args) != 4 {
fmt.Printf("Usage: %s pdf myapp C:\\myapp.exe\n", filepath.Base(os.Args[0]))
os.Exit(1)
}
extension := os.Args[1]
appName := os.Args[2]
exePath := os.Args[3]
sfaKey, err := registry.OpenKey(registry.CLASSES_ROOT, "SystemFileAssociations", registry.CREATE_SUB_KEY)
if err != nil {
panic(err)
}
defer sfaKey.Close()
extKey, _, err := registry.CreateKey(sfaKey, "."+extension, registry.CREATE_SUB_KEY)
if err != nil {
panic(err)
}
defer extKey.Close()
shellKey, _, err := registry.CreateKey(extKey, "shell", registry.CREATE_SUB_KEY)
if err != nil {
panic(err)
}
defer shellKey.Close()
appKey, _, err := registry.CreateKey(shellKey, appName, registry.CREATE_SUB_KEY)
if err != nil {
panic(err)
}
defer appKey.Close()
commandKey, _, err := registry.CreateKey(appKey, "command", registry.WRITE)
if err != nil {
panic(err)
}
defer commandKey.Close()
commandKey.SetStringValue("", exePath+` "%1"`)
}