本文整理汇总了Golang中golang.org/x/sys/windows/registry.OpenKey函数的典型用法代码示例。如果您正苦于以下问题:Golang OpenKey函数的具体用法?Golang OpenKey怎么用?Golang OpenKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenKey函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: isMSOfficeInstalled
func isMSOfficeInstalled() bool {
k, err := registry.OpenKey(registry.CLASSES_ROOT, "Word.Application", registry.QUERY_VALUE)
if err == registry.ErrNotExist {
log.Print(err)
return false
} else {
return true
}
defer k.Close()
return false
}
开发者ID:Silverpeas,项目名称:Silverpeas-OnlineEdition,代码行数:11,代码来源:onlineEditing_windows.go
示例2: getInterfaceRegKey
func (wnic windowsManager) getInterfaceRegKey() (registryKey string, err error) {
//To do: Cleanup, add verbose output
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}`, registry.READ)
if err != nil {
return "", fmt.Errorf("Unable to open registry key: %s", err)
}
defer k.Close()
subkeys, _ := k.ReadSubKeyNames(0) //0 -> read all
for _, subkey := range subkeys {
key, _ := registry.OpenKey(registry.LOCAL_MACHINE, fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\%s`, subkey), registry.READ)
netcfginstanceid, _, _ := key.GetStringValue("NetCfgInstanceId")
if netcfginstanceid == wnic.interfaceID {
key.Close()
k.Close()
return fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\%s`, subkey), nil //Adapter key name is the interface ID
}
key.Close()
}
k.Close()
return "", fmt.Errorf("Unable to find interface registry location for interfaceID '%s'", wnic.interfaceID)
}
开发者ID:evolvedm,项目名称:mac,代码行数:26,代码来源:manager_windows.go
示例3: Location
func Location() (loc SetupLocation, err error) {
var s string
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Hearthstone`, registry.QUERY_VALUE)
if err != nil {
defer k.Close()
s, _, err = k.GetStringValue("DisplayIcon")
}
if err != nil {
k, err = registry.OpenKey(registry.CURRENT_USER, `SOFTWARE\Microsoft\IntelliPoint\AppSpecific\Hearthstone.exe`, registry.QUERY_VALUE)
if err != nil {
defer k.Close()
s, _, err = k.GetStringValue("Path")
if err != nil {
fmt.Printf("Could not determine location")
}
}
}
if err == nil {
root := strings.TrimSuffix(s, "Hearthstone.exe")
loc.LogFolder = filepath.Join(root, "Logs")
} else {
// finally try to stat a well known path
fi, ierr := os.Stat(filepath.Join("C:", "Program Files (x86)", "Hearthstone", "Hearthstone.exe"))
if ierr == nil {
loc.LogFolder = filepath.Dir(fi.Name())
} else {
err = ierr
}
}
loc.Config = filepath.Join(os.ExpandEnv("$LOCALAPPDATA"), "Blizzard", "Hearthstone", "log.config")
return
}
开发者ID:snapbug,项目名称:hearthreplay-client,代码行数:33,代码来源:location_windows.go
示例4: getInterfaceID
func (wnic windowsManager) getInterfaceID() (interfaceID string, err error) { //Fetch interface id from registry
//To do: Cleanup, add verbose output
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}`, registry.READ)
if err != nil {
return "", fmt.Errorf("Unable to open registry: %s\n", err)
}
defer k.Close()
adapterList, _ := k.ReadSubKeyNames(0) //0 -> read all
for _, adapter := range adapterList {
key := fmt.Sprintf(`SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\%s\Connection`, adapter)
subkey, _ := registry.OpenKey(registry.LOCAL_MACHINE, key, registry.READ)
value, _, _ := subkey.GetStringValue("Name")
if value == wnic.InterfaceName {
subkey.Close()
k.Close()
return adapter, nil //Adapter key name is the interface ID
}
subkey.Close()
}
k.Close()
return "", fmt.Errorf("Unable to find interface id for interface '%s'", wnic.InterfaceName)
}
开发者ID:evolvedm,项目名称:mac,代码行数:26,代码来源:manager_windows.go
示例5: getTuntapComponentId
func getTuntapComponentId() (string, error) {
adapters, err := registry.OpenKey(registry.LOCAL_MACHINE, ADAPTER_KEY, registry.READ)
if err != nil {
return "", err
}
var i uint32
for ; i < 1000; i++ {
var name_length uint32 = TAPWIN32_MAX_REG_SIZE
buf := make([]uint16, name_length)
if err = syscall.RegEnumKeyEx(
syscall.Handle(adapters),
i,
&buf[0],
&name_length,
nil,
nil,
nil,
nil); err != nil {
return "", err
}
key_name := syscall.UTF16ToString(buf[:])
adapter, err := registry.OpenKey(adapters, key_name, registry.READ)
if err != nil {
return "", err
}
name := syscall.StringToUTF16("ComponentId")
name2 := syscall.StringToUTF16("NetCfgInstanceId")
var valtype uint32
var component_id = make([]byte, TAPWIN32_MAX_REG_SIZE)
var componentLen = uint32(len(component_id))
if err = syscall.RegQueryValueEx(
syscall.Handle(adapter),
&name[0],
nil,
&valtype,
&component_id[0],
&componentLen); err != nil {
return "", err
}
if unicodeTostring(component_id) == TUNTAP_COMPONENT_ID {
var valtype uint32
var netCfgInstanceId = make([]byte, TAPWIN32_MAX_REG_SIZE)
var netCfgInstanceIdLen = uint32(len(netCfgInstanceId))
if err = syscall.RegQueryValueEx(
syscall.Handle(adapter),
&name2[0],
nil,
&valtype,
&netCfgInstanceId[0],
&netCfgInstanceIdLen); err != nil {
return "", err
}
fmt.Println("Device:", unicodeTostring(netCfgInstanceId))
return unicodeTostring(netCfgInstanceId), nil
}
}
return "", errors.New("not found component id")
}
开发者ID:FlexibleBroadband,项目名称:tun-go,代码行数:59,代码来源:tun_windows.go
示例6: TestCreateOpenDeleteKey
func TestCreateOpenDeleteKey(t *testing.T) {
k, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
if err != nil {
t.Fatal(err)
}
defer k.Close()
testKName := randKeyName("TestCreateOpenDeleteKey_")
testK, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
if err != nil {
t.Fatal(err)
}
defer testK.Close()
if exist {
t.Fatalf("key %q already exists", testKName)
}
testKAgain, exist, err := registry.CreateKey(k, testKName, registry.CREATE_SUB_KEY)
if err != nil {
t.Fatal(err)
}
defer testKAgain.Close()
if !exist {
t.Fatalf("key %q should already exist", testKName)
}
testKOpened, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
if err != nil {
t.Fatal(err)
}
defer testKOpened.Close()
err = registry.DeleteKey(k, testKName)
if err != nil {
t.Fatal(err)
}
testKOpenedAgain, err := registry.OpenKey(k, testKName, registry.ENUMERATE_SUB_KEYS)
if err == nil {
defer testKOpenedAgain.Close()
t.Fatalf("key %q should already been deleted", testKName)
}
if err != registry.ErrNotExist {
t.Fatalf(`unexpected error ("not exist" expected): %v`, err)
}
}
开发者ID:davidsoloman,项目名称:beats,代码行数:49,代码来源:registry_test.go
示例7: main
func main() {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, "SOFTWARE\\INT", registry.QUERY_VALUE)
checkErr(err)
defer k.Close()
Path, _, err = k.GetStringValue("WorkingDirectory")
checkErr(err)
fmt.Printf("%s\n", Path)
svcConfig := &service.Config{
Name: "SphinxMailer",
DisplayName: "SphinxMailer",
Description: "Отправляет письма при обнаружении событий в СКУД Сфинкс.",
}
prg := &program{}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
logger, err = s.Logger(nil)
if err != nil {
log.Fatal(err)
}
err = s.Run()
if err != nil {
logger.Error(err)
}
}
开发者ID:Cobolock,项目名称:GoGO,代码行数:31,代码来源:service.go
示例8: find
func find(fontname string) (filename string, err error) {
keyname := "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"
key, err := registry.OpenKey(registry.LOCAL_MACHINE, keyname, registry.READ)
if err != nil {
return "", fmt.Errorf("cannot open fonts registry key: %s", err)
}
valuenames, err := key.ReadValueNames(0) // 0 means all
if err != nil {
return "", fmt.Errorf("cannot read font names from registry: %s", err)
}
for _, valuename := range valuenames {
name := strings.TrimSpace(strings.TrimSuffix(valuename, "(TrueType)"))
if name != fontname {
continue
}
value, valuetype, err := key.GetStringValue(valuename)
if err != nil {
return "", fmt.Errorf("cannot read font key value (%s of type %d): %s", valuename, valuetype, err)
}
if !filepath.IsAbs(value) {
value = filepath.Join(os.Getenv("windir"), "Fonts", value)
}
return value, nil
}
return "", fmt.Errorf("cannot find font name: %s", fontname)
}
开发者ID:infogulch,项目名称:fontutil,代码行数:26,代码来源:find_windows.go
示例9: Install
// Install modifies PC registry to allow logging with an event source src.
// It adds all required keys and values to the event log registry key.
// Install uses msgFile as the event message file. If useExpandKey is true,
// the event message file is installed as REG_EXPAND_SZ value,
// otherwise as REG_SZ. Use bitwise of log.Error, log.Warning and
// log.Info to specify events supported by the new event source.
func Install(src, msgFile string, useExpandKey bool, eventsSupported uint32) error {
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.CREATE_SUB_KEY)
if err != nil {
return err
}
defer appkey.Close()
sk, alreadyExist, err := registry.CreateKey(appkey, src, registry.SET_VALUE)
if err != nil {
return err
}
defer sk.Close()
if alreadyExist {
return errors.New(addKeyName + `\` + src + " registry key already exists")
}
err = sk.SetDWordValue("CustomSource", 1)
if err != nil {
return err
}
if useExpandKey {
err = sk.SetExpandStringValue("EventMessageFile", msgFile)
} else {
err = sk.SetStringValue("EventMessageFile", msgFile)
}
if err != nil {
return err
}
err = sk.SetDWordValue("TypesSupported", eventsSupported)
if err != nil {
return err
}
return nil
}
开发者ID:2722,项目名称:lantern,代码行数:40,代码来源:install.go
示例10: TestValues
func TestValues(t *testing.T) {
softwareK, err := registry.OpenKey(registry.CURRENT_USER, "Software", registry.QUERY_VALUE)
if err != nil {
t.Fatal(err)
}
defer softwareK.Close()
testKName := randKeyName("TestValues_")
k, exist, err := registry.CreateKey(softwareK, testKName, registry.CREATE_SUB_KEY|registry.QUERY_VALUE|registry.SET_VALUE)
if err != nil {
t.Fatal(err)
}
defer k.Close()
if exist {
t.Fatalf("key %q already exists", testKName)
}
defer registry.DeleteKey(softwareK, testKName)
setValues(t, k)
enumerateValues(t, k)
testValues(t, k)
testStat(t, k)
deleteValues(t, k)
}
开发者ID:davidsoloman,项目名称:beats,代码行数:31,代码来源:registry_test.go
示例11: queryEventMessageFiles
// queryEventMessageFiles queries the registry to get the value of
// the EventMessageFile key that points to a DLL or EXE containing parameterized
// event log messages. If found, it loads the libraries as a datafiles and
// returns a slice of Handles to the libraries.
func queryEventMessageFiles(providerName, sourceName string) ([]Handle, error) {
// Open key in registry:
registryKeyName := fmt.Sprintf(
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
providerName, sourceName)
key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyName,
registry.QUERY_VALUE)
if err != nil {
return nil, fmt.Errorf("Failed to open HKLM\\%s", registryKeyName)
}
defer func() {
err := key.Close()
if err != nil {
logp.Warn("Failed to close registry key. key=%s err=%v",
registryKeyName, err)
}
}()
logp.Debug("eventlog", "RegOpenKey opened handle to HKLM\\%s, key=%v",
registryKeyName, key)
// Read value from registry:
value, _, err := key.GetStringValue("EventMessageFile")
if err != nil {
return nil, fmt.Errorf("Failed querying EventMessageFile from "+
"HKLM\\%s. %v", registryKeyName, err)
}
value, err = registry.ExpandString(value)
if err != nil {
return nil, err
}
// Split the value in case there is more than one file in the value.
eventMessageFiles := strings.Split(value, ";")
logp.Debug("eventlog", "RegQueryValueEx queried EventMessageFile from "+
"HKLM\\%s and got [%s]", registryKeyName,
strings.Join(eventMessageFiles, ","))
// Load the libraries:
var handles []Handle
for _, eventMessageFile := range eventMessageFiles {
sPtr, err := syscall.UTF16PtrFromString(eventMessageFile)
if err != nil {
logp.Debug("eventlog", "Failed to get UTF16Ptr for '%s'. "+
"Skipping. %v", eventMessageFile, err)
continue
}
handle, err := loadLibraryEx(sPtr, 0, LOAD_LIBRARY_AS_DATAFILE)
if err != nil {
logp.Debug("eventlog", "Failed to load library '%s' as data file. "+
"Skipping. %v", eventMessageFile, err)
continue
}
handles = append(handles, handle)
}
logp.Debug("eventlog", "Returning handles %v for sourceName %s", handles,
sourceName)
return handles, nil
}
开发者ID:bqk-,项目名称:packetbeat,代码行数:63,代码来源:eventlog_windows.go
示例12: Remove
// Remove deletes all registry elements installed by the correspondent Install.
func Remove(src string) error {
appkey, err := registry.OpenKey(registry.LOCAL_MACHINE, addKeyName, registry.SET_VALUE)
if err != nil {
return err
}
defer appkey.Close()
return registry.DeleteKey(appkey, src)
}
开发者ID:2722,项目名称:lantern,代码行数:9,代码来源:install.go
示例13: GetWindowsVersion
func GetWindowsVersion() (string, error) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer k.Close()
version, _, err := k.GetStringValue("SystemRoot")
return version, err
}
开发者ID:jeanlaurent,项目名称:gobuildflags,代码行数:9,代码来源:osversion_windows.go
示例14: RemoveSource
// Remove deletes all registry elements installed for an event logging source.
func RemoveSource(provider, src string) error {
providerKeyName := fmt.Sprintf("%s\\%s", eventLogKeyName, provider)
pk, err := registry.OpenKey(registry.LOCAL_MACHINE, providerKeyName, registry.SET_VALUE)
if err != nil {
return err
}
defer pk.Close()
return registry.DeleteKey(pk, src)
}
开发者ID:ChongFeng,项目名称:beats,代码行数:10,代码来源:install.go
示例15: queryEventMessageFiles
// queryEventMessageFiles queries the registry to get the value of
// the EventMessageFile key that points to a DLL or EXE containing templated
// event log messages. If found, it loads the libraries as a datafiles and
// returns a slice of Handles.
func queryEventMessageFiles(eventLogName, sourceName string) ([]Handle, error) {
// Attempt to find the event message file in the registry and then store
// a Handle to it in the cache, or store nil if an event message file does
// not exist for the source name.
// Open key in registry:
registryKeyName := fmt.Sprintf(
"SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s",
eventLogName, sourceName)
key, err := registry.OpenKey(registry.LOCAL_MACHINE, registryKeyName,
registry.QUERY_VALUE)
if err != nil {
logp.Debug("eventlog", "Failed to open HKLM\\%s", registryKeyName)
return nil, err
}
defer key.Close()
logp.Debug("eventlog", "RegOpenKey opened handle to HKLM\\%s, %v",
registryKeyName, key)
// Read value from registry:
value, _, err := key.GetStringValue("EventMessageFile")
if err != nil {
logp.Debug("eventlog", "Failed querying EventMessageFile from HKLM\\%s", registryKeyName)
return nil, err
}
value, err = registry.ExpandString(value)
if err != nil {
return nil, err
}
// Split the value in case there is more than one file specified.
eventMessageFiles := strings.Split(value, ";")
logp.Debug("eventlog", "RegQueryValueEx queried EventMessageFile from "+
"HKLM\\%s and got %v", registryKeyName, eventMessageFiles)
var handles []Handle
for _, eventMessageFile := range eventMessageFiles {
sPtr, err := syscall.UTF16PtrFromString(eventMessageFile)
if err != nil {
logp.Debug("Failed to get UTF16Ptr for '%s' (%v). Skipping",
eventMessageFile, err)
continue
}
handle, err := loadLibraryEx(sPtr, 0, LOAD_LIBRARY_AS_DATAFILE)
if err != nil {
logp.Debug("eventlog", "Failed to load library '%s' as data file:"+
"%v", eventMessageFile, err)
continue
}
handles = append(handles, handle)
}
logp.Debug("eventlog", "Returning handles %v for sourceName %s",
handles, sourceName)
return handles, nil
}
开发者ID:ruflin,项目名称:winlogbeat,代码行数:60,代码来源:eventlog_windows.go
示例16: notifyRegChange
func notifyRegChange(key registry.Key, path string, notifyCh chan error) (err error) {
k, err := registry.OpenKey(key, path, syscall.KEY_NOTIFY)
if err != nil {
return
}
for {
regNotifyChangeKeyValue.Call(uintptr(k), 0, 0x00000001|0x00000004, 0, 0)
notifyCh <- nil
}
}
开发者ID:koofr,项目名称:autoproxy,代码行数:10,代码来源:autoproxy_windows.go
示例17: getNativeDriver
func getNativeDriver(service string) (string, error) {
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SYSTEM\CurrentControlSet\services\`+service, registry.QUERY_VALUE)
if err != nil {
return "", err
}
defer k.Close()
v, _, err := k.GetStringValue("ImagePath")
return v, err
}
开发者ID:ololoshka2871,项目名称:serialdeviceenumeratorgo,代码行数:10,代码来源:backend_windows.go
示例18: updateSystemProxySetting
func updateSystemProxySetting() {
k, err := registry.OpenKey(registry.CURRENT_USER, `Software\Microsoft\Windows\CurrentVersion\Internet Settings`, registry.ALL_ACCESS)
if err != nil {
log.Fatal(err)
}
defer k.Close()
k.SetStringValue("ProxyServer", "127.0.0.1:720")
if err != nil {
log.Fatal(err)
}
}
开发者ID:qianlifeng,项目名称:remapper,代码行数:12,代码来源:main.go
示例19: ProxyFromAutoConfig
func ProxyFromAutoConfig(req *http.Request) (proxyUrl *url.URL, err error) {
// check if AutoConfigURL is definded in registry, otherwise no point in spending time to check it
k, err := registry.OpenKey(registry.CURRENT_USER, PathInternetSettings, registry.READ)
if err != nil {
return
}
defer k.Close()
autoConfigURL, _, err := k.GetStringValue("AutoConfigURL")
if err != nil {
// no auto proxy url
return nil, nil
}
res, err := http.Get(autoConfigURL)
if err != nil {
return nil, err
}
vm := otto.New()
vm.Run(res.Body)
vm.Set("url", req.URL)
vm.Set("host", req.URL.Host)
vm.Run("proxy = FindProxyForURL(url, host);")
val, err := vm.Get("proxy")
if err != nil {
return nil, err
}
proxyStr, err := val.ToString()
if err != nil {
return nil, err
}
// parse it
// format reference: https://en.wikipedia.org/wiki/Proxy_auto-config
for _, proxyMaybe := range strings.Split(proxyStr, ";") {
proxyMaybe = strings.ToLower(proxyMaybe)
if strings.Contains(proxyMaybe, "direct") {
return nil, nil
}
proxyMaybe = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(proxyMaybe), "proxy "))
urlMaybe, err := safeParseUrl(proxyMaybe)
if err == nil {
return urlMaybe, err
}
}
return
}
开发者ID:koofr,项目名称:autoproxy,代码行数:52,代码来源:autoproxy_windows.go
示例20: RemoveProvider
// Remove deletes all registry elements installed for an event logging provider.
// Only use this method if you have installed a custom provider.
func RemoveProvider(provider string) error {
// Protect against removing Application.
if provider == Application {
return fmt.Errorf("%s cannot be removed. Only custom providers can be removed.")
}
eventLogKey, err := registry.OpenKey(registry.LOCAL_MACHINE, eventLogKeyName, registry.SET_VALUE)
if err != nil {
return err
}
defer eventLogKey.Close()
return registry.DeleteKey(eventLogKey, provider)
}
开发者ID:ChongFeng,项目名称:beats,代码行数:15,代码来源:install.go
注:本文中的golang.org/x/sys/windows/registry.OpenKey函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论