1
// Copyright 2012 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
12
"github.com/gabriel-samfira/sys/windows"
13
"github.com/gabriel-samfira/sys/windows/registry"
18
Info = windows.EVENTLOG_INFORMATION_TYPE
19
Warning = windows.EVENTLOG_WARNING_TYPE
20
Error = windows.EVENTLOG_ERROR_TYPE
23
const addKeyName = `SYSTEM\CurrentControlSet\Services\EventLog\Application`
25
// Install modifies PC registry to allow logging with an event source src.
26
// It adds all required keys and values to the event log registry key.
27
// Install uses msgFile as the event message file. If useExpandKey is true,
28
// the event message file is installed as REG_EXPAND_SZ value,
29
// otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and
30
// log.Info to specify events supported by the new event source.
31
func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error {
32
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY)
38
sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE)
44
return errors.New(addKeyName + `\` + src + " registry key already exists")
47
err = sk.SetDWordValue("CustomSource", 1)
52
err = sk.SetExpandStringValue("EventMessageFile", msgFile)
54
err = sk.SetStringValue("EventMessageFile", msgFile)
59
err = sk.SetDWordValue("TypesSupported", eventsSupported)
66
// InstallAsEventCreate is the same as Install, but uses
67
// %SystemRoot%\System32\EventCreate.exe as the event message file.
68
func InstallAsEventCreate(src string, eventsSupported uint32) error {
69
return Install(src, "%SystemRoot%\\System32\\EventCreate.exe", true, eventsSupported)
72
// Remove deletes all registry elements installed by the correspondent Install.
73
func Remove(src string) error {
74
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE)
79
return registry.DeleteKey(appkey, src)