-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathparseStartMenu.go
executable file
·51 lines (44 loc) · 1.1 KB
/
parseStartMenu.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"
"github.com/parsiya/golnk"
)
// Sample program to parse all lnk files in the "All Users" start menu at
// C:\ProgramData\Microsoft\Windows\Start Menu\Programs.
func main() {
startMenu := "C:/ProgramData/Microsoft/Windows/Start Menu/Programs"
basePaths := []string{}
err := filepath.Walk(startMenu, func(path string, info os.FileInfo, walkErr error) error {
// Only look for lnk files.
if filepath.Ext(info.Name()) == ".lnk" {
f, lnkErr := lnk.File(path)
// Print errors and move on to the next file.
if lnkErr != nil {
fmt.Println(lnkErr)
return nil
}
var targetPath = ""
if f.LinkInfo.LocalBasePath != "" {
targetPath = f.LinkInfo.LocalBasePath
}
if f.LinkInfo.LocalBasePathUnicode != "" {
targetPath = f.LinkInfo.LocalBasePathUnicode
}
if targetPath != "" {
fmt.Println("Found", targetPath)
basePaths = append(basePaths, targetPath)
}
}
return nil
})
if err != nil {
panic(err)
}
// Print everything.
fmt.Println("------------------------")
for _, p := range basePaths {
fmt.Println(p)
}
}