-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
71 lines (56 loc) · 1.3 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
package main
import (
"encoding/json"
"fmt"
"github.com/ceshihao/windowsupdate"
"github.com/go-ole/go-ole"
"github.com/scjalliance/comshim"
)
func main() {
comshim.Add(1)
defer comshim.Done()
// ole.CoInitialize(0)
ole.CoInitializeEx(0, ole.COINIT_APARTMENTTHREADED|ole.COINIT_SPEED_OVER_MEMORY)
defer ole.CoUninitialize()
var err error
session, err := windowsupdate.NewUpdateSession()
if err != nil {
panic(err)
}
// Search Updates
fmt.Println("Step 1: Search Updates")
searcher, err := session.CreateUpdateSearcher()
if err != nil {
panic(err)
}
result, err := searcher.Search("IsInstalled=1")
if err != nil {
panic(err)
}
b, _ := json.Marshal(result)
fmt.Println(string(b))
// Download Updates
fmt.Println("Step 2: Download Updates")
downloader, err := session.CreateUpdateDownloader()
if err != nil {
panic(err)
}
downloadResult, err := downloader.Download(result.Updates)
if err != nil {
panic(err)
}
c, _ := json.Marshal(downloadResult)
fmt.Println(string(c))
// Install Updates
fmt.Println("Step 3: Install Updates")
installer, err := session.CreateUpdateInstaller()
if err != nil {
panic(err)
}
installationResult, err := installer.Install(result.Updates)
if err != nil {
panic(err)
}
d, _ := json.Marshal(installationResult)
fmt.Println(string(d))
}